スタイルを設定したいカスタムコントロールがあります。
これは、TextBoxと別のインターフェイスから継承する単なるクラスであり、インターフェイスは追加のプロパティを追加するだけです。
このカスタムコントロールにスタイルを適用して、読み取り専用プロパティが設定されている場合に背景が灰色になるようにするにはどうすればよいですか?
public class DionysusTextBox : TextBox, IDionysusControl
{
public DionysusTextBox()
{
SetStyle();
}
#region IDionysusControl Members
public bool KeepReadOnlyState
{
get { return (bool)GetValue(KeepReadOnlyStateProperty); }
set { SetValue(KeepReadOnlyStateProperty, value); }
}
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty KeepReadOnlyStateProperty =
DependencyProperty.Register("KeepReadOnlyState", typeof(bool), typeof(DionysusTextBox), new UIPropertyMetadata(true));
#endregion
#region Style
Style styleListBoxItem = new Style(typeof(DionysusTextBox));
Trigger triggerReadonly = new Trigger { Property = DionysusTextBox.IsReadOnlyProperty, Value = true };
private void SetStyle()
{
triggerReadonly.Setters.Add(new Setter(DionysusTextBox.BackgroundProperty, Brushes.Black));
this.Triggers.Add(triggerReadonly);
}
#endregion
}
上記はクラス全体のコードです。スタイルの使用方法は適切な方法のように見えましたが、このコントロールをデザイナーに追加すると、次のエラーが発生します。
Triggers collection members must be of type EventTrigger.
誰かが私を正しい方向に向けることができますか?