我想将一个只包含样式的XAML文件合并到我的应用程序的Window.Resource中。我尝试使用MergedDictionaries,如WPF Reference custom resource defined in another xaml file中所描述的。
首先:文件名为"MyStyleDocument.xaml“,包含不同的WPFstyles,而不使用x-键。
<ResourceDictionary
xmlns=" http://schemas.microsoft.com/winfx/2006/xaml/presentation "
xmlns:x=" http://schemas.microsoft.com/winfx/2006/xaml ">
<Style TargetType="{x:Type TabControl}">
(...)
</Style>
<Style TargetType="{x:Type XY}">
(...)
</Style>
.
.
.
</ResourceDictionary>第二:
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="MyStyleDocument.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>我得到的结果是:“在查找资源字典”MyStyleDocument.xaml“时发生了错误。”该文件位于项目的文件夹中。
我的问题是:如何将包含不同样式的XAML文件巧妙地包含到另一个XAML代码中?
我的项目的结构是:WPFApplication( folder1) -> Folder1包含WPFApplication(文件folder2);WPFApplication.sln;WPFApplication.suo;WPFApplication.v11.suo文件文件夹2包括: bin (文件文件夹2.1);obj(文件文件夹2.2);属性(filefolder2.3);App.xaml;App.xaml.cs;Application.ico;MainWindow.xaml.cs;App.xaml WpfApplication.csproj
发布于 2015-08-25 10:44:37
下面是一个wpf演示项目:
-WpfApplication
|--App.xaml
|--MyStyle[here is a floder]
|---MyStyleDocument1.xaml
|---MyStyleDocument2.xaml
|---MyStyleDocument3.xaml然后您可以像这样编辑App.xaml:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!--add style file here like this-->
<ResourceDictionary Source="/MyStyle/MyStyleDocument1.xaml" />
</ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<Application.Resources>https://stackoverflow.com/questions/32125934
复制相似问题