I have an ItemTemplate in which there is a simple button associated with a command that can be executed or is not dependent on any property.
I want the background color of this button to change if the command is not executable. I tried several methods, but I still canβt do it exclusively in XAML (I do this in the context of the study, and the code behind is not allowed).
Here is my code for the button:
<Button x:Name="Dispo" HorizontalAlignment="Center" Margin="0" VerticalAlignment="Center" Width="30" Height="30" Grid.Column="2" Grid.Row="0" Command="{Binding AddEmpruntCommandModel.Command}" CommandParameter="{Binding ElementName='flowCars', Path='SelectedItem'}" vm:CreateCommandBinding.Command="{Binding AddEmpruntCommandModel}" > <Button.Style> <Style TargetType="{x:Type Button}"> <Style.Triggers> <Trigger Property="IsEnabled" Value="True"> <Setter Property="Button.Background" Value="Green"/> </Trigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Button.Background" Value="Red"/> </Trigger> </Style.Triggers> </Style> </Button.Style> </Button>
source share