我需要将应用程序样式分隔为几个xaml文件。 但我也需要在单个文件在其他文件中定义的样式定义一些共同的价值观像winrt xaml合并资源
<x:Double x:Key="SharedValue">100</x:Double>
使用此值。 例如:
<Style x:Name="SomeStyle" TargetType="TextBox">
<Setter Property="Width" Value="{StaticResource SharedValue}"/>
</Style>
和其他资源字典文件:
<Style x:Name="AnotherStyle" TargetType="Button">
<Setter Property="Height" Value="{StaticResource SharedValue}"/>
</Style>
但当我尝试定义在App.xaml中合并资源字典文件
<Application.Resources>
<ResourceDictionary >
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="DefinedValues.xaml"/>
<ResourceDictionary Source="Styles1.xaml"/>
<ResourceDictionary Source="Styles2.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
我得到这个运行异常:“消息=”找不到具有名称/密钥共享值的资源“
你能告诉我这样做是否可行?我做错了什么? 谢谢。
你在哪里看到信息?您是否试图通过{StaticResource}访问XAML中的资源? –
在App.g.i.cs文件中将它作为运行时未处理的异常处理时出现此错误,但intelisence不会将我的SharedValue点亮为任何地方无法识别的。 –
是的,这是可能的,我可以使用你的例子创建一个应用程序,它适用于我的项目。您确定您的App.xaml文件中有DefinedValues.xaml和另外两个ResourceDictionaries的正确路径吗? –