我有一个关于按钮的IsEnabled属性的问题。
这是我的按钮样式:
<Style x:Key="Button_selectable" TargetType="{x:Type Button}">
<Setter Property="FontSize" Value="15"/>
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border CornerRadius="5" Background="{TemplateBinding Background}" BorderThickness="1" BorderBrush="Black" Margin="1,1,1,1">
<Grid>
<ContentPresenter Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Tag, RelativeSource={RelativeSource Self}}" Value="True">
<Setter Property="Background" Value="MediumSlateBlue"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=Tag, RelativeSource={RelativeSource Self}}" Value="False">
<Setter Property="Background" Value="white"/>
</DataTrigger>
</Style.Triggers>
</Style>
使用方法:
<Button Command="{Binding command}" IsEnabled="{Binding Enable}" x:Name="button" Content="Button1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" FontSize="13.333" Style="{StaticResource Button_selectable}" Tag="{Binding State}"/>
没有使用我的样式时,IsEnabled属性能够正常工作。但是如果我使用这个样式,按钮会一直处于启用状态。
我谷歌了好几个小时,但是什么都没找到 :-(
谢谢您的帮助!