5
我在主題/ Generic.xaml中有以下按鈕樣式,我希望它適用於我的WPF應用程序中的任何地方的按鈕。如何將Themes/Generic.xaml連接到window1.xaml?
如何將它連接到我的window1.xaml例如?
<Style TargetType="{x:Type Button}">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="MinHeight" Value="23"/>
<Setter Property="MinWidth" Value="75"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border
x:Name="Border"
CornerRadius="2"
BorderThickness="1"
Background="#C0C0C0"
BorderBrush="#404040">
<ContentPresenter
Margin="2"
HorizontalAlignment="Center"
VerticalAlignment="Center"
RecognizesAccessKey="True"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsKeyboardFocused" Value="true">
<Setter TargetName="Border" Property="BorderBrush" Value="#202020" />
</Trigger>
<Trigger Property="IsDefaulted" Value="true">
<Setter TargetName="Border" Property="BorderBrush" Value="#202020" />
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="Border" Property="Background" Value="#808080" />
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="Border" Property="Background" Value="#E0E0E0" />
<Setter TargetName="Border" Property="BorderBrush" Value="#606060" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter TargetName="Border" Property="Background" Value="#EEEEEE" />
<Setter TargetName="Border" Property="BorderBrush" Value="#AAAAAA" />
<Setter Property="Foreground" Value="#888888"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我知道這是一個老問題...但我會建議,如果你只是想改變默認的按鈕樣式...你將上述xaml移動到你的App.xaml文件。 Generic.xaml具有作爲WPF主題樣式的回退機制的特定目的。查看下面的鏈接(通過歌曲)到另一個StackOverflow文章,瞭解更多關於此主題的信息。 – cplotts 2011-01-14 21:02:51
哎呀,Muad'Dib的答案在下面......有點隱含地暗示着我在說......通過合併DefaultStyles.xaml來代替Generic.xaml。 :-) – cplotts 2011-01-14 21:06:59