我已经定义了一个依赖属性,它使用枚举来更新按钮的背景颜色。当它运行时,我得到一个“默认值类型与属性类型‘CurrentWarningLevel’不匹配”异常。依赖属性如下:
public enum WarningLevels
{
wlError=0,
wlWarning,
wlInfo
};
public class WarningLevelButton : Button
{
static WarningLevelButton()
{
}
public WarningLevels CurrentWarningLevel
{
get { return (WarningLevels)GetValue(WarningLevelProperty); }
set { base.SetValue(WarningLevelProperty, value); }
}
public static readonly DependencyProperty WarningLevelProperty =
DependencyProperty.Register("CurrentWarningLevel", typeof(WarningLevels), typeof(WarningLevelButton), new PropertyMetadata(false));
}
我正在尝试按如下方式使用该属性:
<Trigger Property="local:WarningLevelButton.CurrentWarningLevel" Value="wlError">
<Setter TargetName="ButtonBody" Property="Background" Value="{StaticResource CtlRedBrush}" />
<Setter TargetName="ButtonBody" Property="BorderBrush" Value="{StaticResource CtlRedBrush}" />
</Trigger>
<Trigger Property="local:WarningLevelButton.CurrentWarningLevel" Value="wlWarning">
<Setter TargetName="ButtonBody" Property="Background" Value="{StaticResource GreyGradientBrush}" />
<Setter TargetName="ButtonBody" Property="BorderBrush" Value="{StaticResource BorderBrush}" />
</Trigger>