I made this style for my button and it is loaded fine
but I now try to have a different background depending on the IsEnabled property and this does not seem to work
<SolidColorBrush x:Key="Color" Color="#FFADD2CC"/>
<SolidColorBrush x:Key="Color_Disabled" Color="#FF8D9B98"/>
<Style x:Key="ButtonStyle" TargetType="Button">
<Setter Property="Height" Value="32"/>
<Setter Property="Padding" Value="8,4,8,4"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}">
<Grid>
<Rectangle x:Name="BackgroundRect" Fill="{StaticResource Color}" RadiusX="2" RadiusY="2"/>
<ContentPresenter Margin="{TemplateBinding Padding}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</Border>
<ControlTemplate.Triggers>
<!-- DataTrigger to change the background color based on IsEnabled property -->
<DataTrigger Binding="{Binding IsEnabled, RelativeSource={RelativeSource TemplatedParent}}" Value="True">
<Setter TargetName="BackgroundRect" Property="Fill" Value="{StaticResource Color}"/>
</DataTrigger>
<DataTrigger Binding="{Binding IsEnabled, RelativeSource={RelativeSource TemplatedParent}}" Value="False">
<Setter TargetName="BackgroundRect" Property="Fill" Value="{StaticResource Color_Disabled}"/>
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I use it in my main template like this
<Button Grid.Column="1" Content="Button Text" ToolTip="Some tooltip" Click="OnClick" Style="{StaticResource ButtonStyle}" Margin="0,0,4,0" IsEnabled="false"/>
I expect the button to be a different color depending on the IsEnabled value
thanks for your help