在Windows应用商店应用程序中,我无法通过StaticResource绑定在一个资源字典中将资源用作第二个资源字典样式中属性设置器的值。Windows Store应用程序 - 资源字典样式问题
这里是什么,我试图做一个例子:
Dictionary1.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="SomeBrush" Color="Black" />
</ResourceDictionary>
Dictionary2.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="SomeStyle" TargetType="Button">
<Setter Property="Foreground" Value="{StaticResource SomeBrush}" />
</Style>
</ResourceDictionary>
的App.xaml
<Application
x:Class="TestApp.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="Common/StandardStyles.xaml"/>
<ResourceDictionary Source="Common/Dictionary1.xaml"/>
<ResourceDictionary Source="Common/Dictionary2.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
无论我做什么,这都行不通。该应用程序不会启动,而是抛出未处理的异常,导致“带键的资源'SomeBrush'无法找到”。
我试图改变App.xaml中的顺序,以嵌套合并字典玩,等
我有设法得到它做这个工作,但是这是不是一种选择:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionary1.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style x:Key="SomeStyle" TargetType="Button">
<Setter Property="Foreground" Value="{StaticResource SomeBrush}" />
</Style>
</ResourceDictionary>
在运行时,App.Resources.MergedDictionaries被清除,各种资源字典是根据各种条件动态加载。 Dictionary1.xaml和Dictionary2.xaml都是相互独立加载的,根据这些条件可能包含不同的资源,因此以这种方式合并它们不是一种选择。它们必须在设计时包含在App.xaml中以支持....设计。
有没有人知道这里发生了什么?这是一个错误?
谢谢!