在另一个xaml文件中编写样式并将该对象归属于另一个xaml页面是不可行的吗? [英] is it impassible to write style in another xaml file and attribute the object in another xaml page?
本文介绍了在另一个xaml文件中编写样式并将该对象归属于另一个xaml页面是不可行的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在另一个xaml文件中编写样式并将该对象归属于另一个xaml页面?
Is it possible to write style in another xaml file and attribute the object in another xaml page?
推荐答案
你的意思是你想把你的xaml样式放入一个文件并在另一个文件中使用?是。
你可以做到这一点。您可以创建一个ResourceDictionary来保存您的样式并被许多其他文件使用。你只需要将它作为资源包含在每个文件中,或者你可以将它添加到app.xaml中的Application.Resources然后它将可用于整个应用程序。
Do you mean you want to put your xaml styles in one file and use them in another? yes.
you can do that. You can create a ResourceDictionary to hold your styles and be used by many other files. you just need to include it as a resource in each file or you can add it to the Application.Resources in your app.xaml then it will be available to the entire application.
<Application x:Class="myNameSpace.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/SomeDllWithResource;component/Layout/WPFDataGridLayout.xaml" />
<ResourceDictionary Source="myResources.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
一旦你创建了资源字典,就可以像上面的'myResources.xaml'那样包含它,该行可以放在特定文件的资源部分或app.xaml中上面的例子。
once you've created the Resource dictionary you can include it like above for 'myResources.xaml' that line can be put in the resources section of a specific file or in the app.xaml like the example above.
这篇关于在另一个xaml文件中编写样式并将该对象归属于另一个xaml页面是不可行的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文