I have a Custom UserControl that extends the button control and adds two new dependency properites IsActive and Icon. In the control there are DataTriggers that set the Icon and the Active state based on the value.
The issue I am having is that the control only working inside of an ItemControl. Here is the XAML portion of the control in and outside of a Items Control. The triggers are not working when the control is not in the item control.
<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}" />
Here is the DataTrigger in the Control.
<DataTrigger Binding="{Binding ElementName=MyFunctionButton, Path=Icon}" Value="Home">
<Setter TargetName="HomeIcon" Property="Visibility" Value="Visible" />
</DataTrigger>
The only properties that are not working are my dependency Properties.
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);
}
}
Any help would be much appreciated.