4
我有几种常见样式,我想在我的Windows 8.1应用程序的多个页面中共享它们。如何使用ResourceDictionary中定义的样式
我知道我可以用merge dictionaries option来实现,但我不知道如何使用字典中定义的样式。
我尝试这样做:
<Page.Resources>
<ResourceDictionary x:Key="lol">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/Generic.xaml" />
<ResourceDictionary>
<Style x:Key="TextViewAllStyle" TargetType="TextBlock">
</Style>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
<Style x:Key="TextViewAllStyle2" TargetType="TextBlock">
</Style>
</ResourceDictionary>
<Style x:Key="TextViewAllStyle3" TargetType="TextBlock">
</Style>
</Page.Resources>
但我的Visual Studio中只能看到第三个......
<TextBlock Style="{StaticResource ResourceKey=TextViewAllStyle3}"/>
它给我一个错误的资源属性仅可一次设定。 – C4u
您可能已在资源标签中定义了多个词典或其他资源。如果你将它们移动到MergedDictionaries,它应该没问题。请参阅此链接http://stackoverflow.com/a/3425956/366064 – Bijan
感谢您的回复。我发现我的问题。远离形成定义的字典,我仍然努力在我的app.xaml内的一些自定义样式。我只需要在Merde-block中用''将它们包围起来。一切安好 :)。 –
C4u