我有一个自定义用户控件,它扩展了按钮控件,并添加了两个新的依赖项IsActive和Icon。在控件中有DataTrigger,它们根据该值设置Icon和Active状态。WPF DataTrigger没有射出ItemsControl外
我遇到的问题是仅在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);
}
}
任何帮助将不胜感激。
它也适用于 <控件模板> <控件:FunctionButton IsActive = “真” 前景= “白” CONTENT = “家” 图标= “家” 命令=” {结合的HomeClick}” /> 控件模板> ContentControl中> 看起来像蛋类问题之前鸡。 –
cjibo
2010-03-01 19:50:44