赞
踩
在WPF中,要为按钮创建一个禁用样式,需要在资源字典中定义一个Style
,该样式将应用于Button
控件的IsEnabled
属性为False
时的状态。
以下是一个简单的例子:
<Style TargetType="Button" x:Key="NormalButtonStyle">
<Setter Property="Foreground" Value="White"/>
<Setter Property="Width" Value="50"/>
<Setter Property="Height" Value="30"/>
<Setter Property="Background" Value="#FF0ABEFF"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="4">
<Border Background="Transparent" Name="back" CornerRadius="4">
<ContentPresenter VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"/>
</Border>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#11000000" TargetName="back"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="Button.IsEnabled" Value="False">
<Setter Property="Background" Value="Gray"/>
</Trigger>
</Style.Triggers>
</Style>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。