I have an enum that looks like this:
namespace CryptoRecovery.Models.Experiment.Cells
{
public enum ExperimentState
{
On,
Off
}
}
I have a UserControl
that looks like :
<UserControl x:Class="CryptoRecovery.Views.Experiments.OnOffSwitch"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:cells="clr-namespace:CryptoRecovery.Models.Experiment.Cells"
mc:Ignorable="d" >
<Border Height="30" Width="81" CornerRadius="15" BorderThickness="1">
<Border.Style>
<Style TargetType="Border">
<Setter Property="BorderBrush" Value="{StaticResource OffColorBrush}"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=State, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}" Value="{x:Static cells:ExperimentState.On}">
<Setter Property="BorderBrush" Value="{StaticResource OnColorBrush}"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
<TextBlock Text="{Binding Path=State}" FontSize="20" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Foreground" Value="{StaticResource OffColorBrush}"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=State, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}" Value="On">
<Setter Property="Foreground" Value="{StaticResource OnColorBrush}"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</Border>
</UserControl>
My DataTriggers do not change the colors.
I have tried to change the import statement from:
xmlns:cells="clr-namespace:CryptoRecovery.Models.Experiment.Cells"
to
xmlns:cells="clr-namespace:CryptoRecovery.Models.Experiment.Cells;assembly=CryptoRecovery.Models"
and it did not compile.
public partial class OnOffSwitch : UserControl
{
public OnOffSwitch()
{
InitializeComponent();
}
public static readonly DependencyProperty StateProperty = DependencyProperty.Register(
"State", typeof(ExperimentState), typeof(OnOffSwitch), new FrameworkPropertyMetadata(default(ExperimentState), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
public ExperimentState State
{
get { return (ExperimentState) GetValue(StateProperty); }
set { SetValue(StateProperty, value); }
}
}