On 2008-06-06, star-italia <star-italia@xxxxxx> wrote:
Quote:
> Tom Shelton wrote: Quote:
>> On 2008-06-06, star-italia <star-italia@xxxxxx> wrote: Quote:
>>> Hi, Is it possible to include a XAML file into another XAML file?
>>>
>>> For example If i have
>>> - Window1.xaml
>>> - Window2.xaml
>>>
>>> and both have a treeview with a custom Style, can i describe the style
>>> in a trvStyle.xaml and then include it in both windows?
>>>
>>> Thanks in advance
>>
>> I don't know of anyway to do that (that doesn't mean there isn't
-
>> but If this is the same application, you could define the style
>> in the application resources, and then it will be available globablly.
>> >
> And what if i want to create a control in XAML and then reuse it in
> another window?
>
> And to be more precise, I'm loading XAML on the fly, so I'd not want to
> load it as a resource. However thanks for your reply 
If your loading it on the fly, then you would have to use some procedural
code, and do something like this...
Create the trvStyle.xaml:
<ResourceDictionary
xmlns="http://......"
xmlns:x="http://...." >
<Style x:Key="TreeViewStyle" TargetType="{x:Type TreeView}">
<!-- do your style stuff here -->
</Style>
</ResourceDictionary>
<Window x:Name="Window1" ...>
....
<TreeView Style="{DynamicResource TreeViewStyle}">
...
</TreeView>
</Window>
Then you need to load the style dynamically (XamlReader.Load) the resource
dictionary and then either replace the Application.Current.Resources (or what
ever ResourceDictionary your interested in) or you could merge them together.
Adding or replacing the enteries with those from the dynamically loaded
dictionary.
HTH
--
Tom Shelton