Can I do it without overriding button's template only with styles?
I think not, because the Controls in the Windows has a default Styles
and ControlTemplates
and in each version of Windows they are different. In addition, the styles - it's just a lot of settings, usually the style does not change/add behavior to control, which is responsible for this ControlTemplate
.
Note:
the Style it is a set of setters, for example: set the background, size, etc. The ControlTemplate
is the form, in which all of these settings will appear.
In this situation, I recommend you all to change the ControlTemplate, where it is possible to have the same behavior aka view, regardless of the version of the system.
In this case, try this Style
:
<Window.Resources>
<Style TargetType="Button" x:Key="MyButton2">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Background" Value="MediumAquamarine" />
<Setter Property="Foreground" Value="MediumBlue" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid Background="{TemplateBinding Background}">
<ContentPresenter x:Name="MyContentPresenter"
Content="{TemplateBinding Content}"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="Green"/>
<Setter Property="Foreground" Value="DeepPink"/>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid x:Name="LayoutRoot">
<Button Content="Button"
IsEnabled="False"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Width="75"
Style="{StaticResource MyButton2}"
Click="Button_Click"/>
</Grid>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…