![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| Guest | Is it possible to include XAML files into another XAML file? 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 |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Is it possible to include XAML files into another XAML file? 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 -but If this is the same application, you could define the style in the application resources, and then it will be available globablly. -- Tom Shelton |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: Is it possible to include XAML files into another XAML file? 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. > 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 ![]() |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: Is it possible to include XAML files into another XAML file? 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 ![]() 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 |
My System Specs![]() |
| | #5 (permalink) |
| Guest | Re: Is it possible to include XAML files into another XAML file? Tom Shelton wrote: Quote: > 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: >>>> 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. >>> >> 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 > |
My System Specs![]() |
| | #6 (permalink) |
| Guest | Re: Is it possible to include XAML files into another XAML file? Hello star-italia and Tom, XamlReader.Load() can do the task when the resource dictionary is in a loose XAML form. However, if the resource dictionary is compiled into BAML, we need to use the Application.LoadComponent() method to de-serialize it into ResourceDictionary object, then add it to either Application.Current.Resources or Window.Resources dictionary through the MergedDictionaries property: ResourceDictionary resourceDictionary = Application.LoadComponent(new Uri("CommonResources.xaml", UriKind.Relative)) as ResourceDictionary; if (resourceDictionary != null) { Application.Current.Resources.MergedDictionaries.Add(resourceDictionary); } When the resource is merged into the Application level, we use StaticResource or DynamicResource to refer to them in either Window1.xaml or Widnow2.xaml files. The code above can also be written in Window1 or Window2 constructor at codebehind as follows: ResourceDictionary resourceDictionary = Application.LoadComponent(new Uri("CommonResources.xaml", UriKind.Relative)) as ResourceDictionary; if (resourceDictionary != null) { this.Resources.MergedDictionaries.Add(resourceDictionary); } In this way, the window will have a separate copy of the resource dictionaries, though this might not be very efficient considering the consumption of the memory. If you plan to merge resources completely in XAML, we can directly specify the MergedDictionary in XAML as follows: <App.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack uri to the resource dictionary xaml file"/> </ResourceDictionary.MergedDictionaries </ResourceDictionary> </ App.Resources> One caveat here is that you define the Visuals like Button in the resource dictionary as follows: <Button x:Key="button"/> Because one Visual can have only one visual parent, we cannot re-parented it for multiple times in the visual tree, so that if the "button" resource is going to be reused in multiple places, please specify the x:Shared property to "False" when declaring the Button resource as this: <Button x:Shared="False" x:key="button"/> x:Shared means that, every time this "button" resource is applied, WPF will create a unique copy. But when x:Shared is specified, resource dictionary should be compiled into BAML beforehand. So if you are using loose, non-compiled XAML, please ignore my suggestion. Regards, Jialiang Ge (jialge@xxxxxx, remove 'online.') Microsoft Online Community Support Delighting our customers is our #1 priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please feel free to let my manager know what you think of the level of service provided. You can send feedback directly to my manager at: msdnmg@xxxxxx. ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscripti...ult.aspx#notif ications. Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscripti...t/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. |
My System Specs![]() |
| | #7 (permalink) |
| Guest | Re: Is it possible to include XAML files into another XAML file? Hi Star-italia, How about the problem now? If you have any question, please feel free to let us now. Thank you for using our MSDN Managed Newsgroup Support Service! Sincerely, Linda Liu Microsoft Online Community Support Delighting our customers is our #1 priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please feel free to let my manager know what you think of the level of service provided. You can send feedback directly to my manager at: msdnmg@xxxxxx. This posting is provided "AS IS" with no warranties, and confers no rights. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Event in Xaml vs c# file. | .NET General | |||