有没有办法为应用程序中的任何控件设置默认FontStyle。 我在Generic.xaml中为TextBlock设置了默认样式,但是当我在应用程序中设置textBlock的任何属性时,它开始使用主parrent样式,但不是我的样式改变了一些属性。 有没有办法将我的样式设置为所有TextBlocks的主要样式?
答案 0 :(得分:2)
是的。简单地说,创建一个“匿名”样式并将其加载到App.xaml
中。你可能想看看here。在下文中,您可以找到我常用的方法。
<强> Style.xaml 强>
<ResourceDictionary ...>
<!-- a non anonymous style as base for all styles you may want to derive -->
<Style x:Key="TextBlockDefault" TargetType="TextBlock">
<!-- every default property you want to set -->
</ Style>
<!-- now the anonymous style (no key attribute) -->
<Style BasedOn="{StaticResource TextBlockDefault}" TargetType="TextBlock" />
</ResourceDictionary>
<强>的App.xaml 强>
<Application ...>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/<yourAppName>;component/<path>/Style.xaml" />
</ ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>