我有一个WPF .net 4.5应用程序,我在合并资源字典时遇到问题.
我有与此问题和本问题完全相同的问题,但接受的解决方案对我不起作用.
我在app.xaml中声明了一个资源字典,如下所示(为简洁起见,简化):
<Application.Resources>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Skin/ResourceLibrary.xaml" />
<ResourceDictionary Source="Skin/Brushes/ColorStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)
问题: 应用程序可以在app.xaml中列出时"查看"ColorStyles dictonary,但是如果我将其移动/嵌套在ResourceLibrary.xaml中,则应用程序不会"看到"ColorStyles.xaml以及有关缺少静态资源的错误出现.
以下是我创建ResourceLibrary.xaml字典的方法(简化):
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<!-- BRUSHES AND COLORS -->
<ResourceDictionary Source="Brushes/ColorStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)
更改原因:我当前的资源字典组织很糟糕,我需要更改它(因为我不止一次创建对象).我希望在"Skin"文件夹中有一个资源字典,然后在子文件夹中组织剩余的样式字典,这些字典将全部合并到ResourceLibrary.xaml文件中,而后者将在app.xaml中调用.
我尝试过: 是的我尝试使用上面链接中的解决方案:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Skin/ResourceLibrary.xaml"/>
</ResourceDictionary.MergedDictionaries>
<!-- Dummy Style, anything you won't use goes -->
<Style TargetType="{x:Type Rectangle}" />
</ResourceDictionary>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)
但我在虚拟样式行上得到以下错误:
错误2属性元素不能位于元素内容的中间.它们必须在内容之前或之后.
由于lisp注释,将代码更改为以下内容消除了上述错误:
<Application.Resources>
<ResourceDictionary>
<!--Global View Model Locator-->
<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
<!-- Dummy Style, anything …Run Code Online (Sandbox Code Playgroud)