ボタン コントロールを拡張し、2 つの新しい依存プロパティ IsActive と Icon を追加するカスタム UserControl があります。コントロールには、値に基づいて Icon と Active 状態を設定する DataTrigger があります。
私が抱えている問題は、コントロールが ItemControl 内でのみ機能することです。以下は、Items コントロール内外のコントロールの XAML 部分です。コントロールが項目コントロールにない場合、トリガーは機能しません。
<ItemsControl ItemsSource="{Binding HomeList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Controls:FunctionButton IsActive="True" Foreground="White" Content="Home" Icon="Home" Command="{Binding HomeClick}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<Controls:FunctionButton IsActive="True" Foreground="White" Content="Home" Icon="Home" Command="{Binding HomeClick}" />
コントロールの DataTrigger を次に示します。
<DataTrigger Binding="{Binding ElementName=MyFunctionButton, Path=Icon}" Value="Home">
<Setter TargetName="HomeIcon" Property="Visibility" Value="Visible" />
</DataTrigger>
機能していない唯一のプロパティは、私の依存関係のプロパティです。
public static readonly DependencyProperty IsActiveProperty = DependencyProperty.Register("IsActive", typeof(bool), typeof(FunctionButton));
public static readonly DependencyProperty IconProperty = DependencyProperty.Register("Icon", typeof (Icon), typeof (FunctionButton));
/// <summary>
/// Gets or sets a value indicating whether this instance is active.
/// </summary>
/// <value><c>true</c> if this instance is active; otherwise, <c>false</c>.</value>
public bool IsActive
{
get
{
return (bool) base.GetValue(IsActiveProperty);
}
set
{
base.SetValue(IsActiveProperty, value);
}
}
/// <summary>
/// Gets or sets the icon.
/// </summary>
/// <value>The icon.</value>
public Icon Icon
{
get
{
return (Icon) base.GetValue(IconProperty);
}
set
{
base.SetValue(IconProperty, value);
}
}
どんな助けでも大歓迎です。