4
我有一个ItemTemplate,其中是一个简单的按钮绑定在一个命令,可以执行或不取决于某些属性。如何根据绑定命令更改按钮背景颜色canexecute?
我想要这个按钮的背景颜色改变,如果命令不可执行。 我尝试了几种方法,但我无法找到纯粹在XAML中完成的操作(我在学习上下文中执行此操作,并且不允许使用代码)。
下面是我对按钮的代码:
<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>