<Window.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="FontFamily" Value="Times New Roman" />
<Setter Property="FontSize" Value="30" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Background" Value="#FFCA5132" />
</Style>
</Window.Resources>
This aboved cod开发者_如何转开发e looks like the right selection to apply WPF style to all buttons in a specific window. But I want to apply this style for all buttons in my program.
I think I need to write down this code in the <Application.Resources></Application.Resources>
. But it doesn't run. How can I do that?
<Application.Resources>
is a ResourceDictionary
. You can't add to it both a ResourceDictionary
and a Style
, like you are doing in your code. Place the Style
inside the ResourceDictionary
, like this:
<Application.Resources>
<ResourceDictionary Source="/PresentationFramework.Aero
, Version=3.0.0.0,Culture=neutral
, PublicKeyToken=31bf3856ad364e35
, ProcessorArchitecture=MSIL;component/themes/aero.normalcolor.xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Style\AppStyle.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="{x:Type Button}">
<Setter Property="FontFamily" Value="meiryo" />
<Setter Property="FontSize" Value="12" />
</Style>
</ResourceDictionary>
</Application.Resources>
精彩评论