MyUserControlというカスタムユーザーコントロールを作成しています。いくつかのMyUserControlが複数回定義されているメインウィンドウで使用するDependecyPropertiesがたくさんあります。私が知りたいのは、スタイルのトリガー/プロパティが起動するカスタムプロパティを作成するにはどうすればよいですか?
たとえば、カスタムプロパティBOOL IsGoingとカスタムプロパティMyBackgroung(UserControlの背景)がある場合、どちらも次のように定義されます。
public bool IsGoing
{
get { return (bool)this.GetValue(IsGoingProperty); }
set { this.SetValue(IsGoingProperty, value); }
}
public static readonly DependencyProperty IsGoingProperty = DependencyProperty.RegisterAttached(
"IsGoing", typeof(bool), typeof(MyUserControl), new PropertyMetadata(false));
public Brush MyBackground
{
get { return (Brush)this.GetValue(MyBackgroundProperty); }
set { this.SetValue(MyBackgroundProperty, value); }
}
public static readonly DependencyProperty MyBackgroundProperty = DependencyProperty.Register(
"MyBackground", typeof(Brush), typeof(MyUserControl), new PropertyMetadata(Brushes.Red));
また、MainWindow.xamlでUserControlを定義した場合、IsGoingプロパティがtrue / falseであるかどうかに応じて、トリガーにアクセスしてMyBackgroundを設定するにはどうすればよいですか?私は多くのことを試みましたが、本質的には、次のようなことを達成しようとしています。
<custom:MyUserControl MyBackground="Green" x:Name="myUC1" Margin="120.433,0,0,65.5" Height="50" Width="250" VerticalAlignment="Bottom" HorizontalAlignment="Left" >
<Style>
<Style.Triggers>
<Trigger Property="IsGoing" Value="True">
<Setter Property="MyBackground" Value="Yellow"/>
</Trigger>
</Style.Triggers>
</Style>
</custom:MyUserControl>
私の説明があなたが理解するのに十分良いことを願っています。私はこれに数日間取り組んできましたが、解決策が見つからないようです。助けてくれてありがとう!!!
エイドリアン