列挙型を使用してボタンの背景色を更新する依存関係プロパティを定義しました。実行すると、「デフォルト値のタイプがプロパティ '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>