我有一个自定义用户控件,它扩展了按钮控件并添加了两个新的依赖属性 IsActive 和 Icon。在控件中有根据值设置图标和活动状态的 DataTriggers。
我遇到的问题是该控件仅在 ItemControl 内部工作。这是项目控件内外的控件的 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);
}
}
任何帮助将非常感激。