I have a MVVM binding for Border background where in I read Color names from a file in String format and convert them to Brush using the code:
Brush b1 = new SolidColorBrush((Color)ColorConverter.ConvertFromString("Red");
myItem.Background = b1;
Background is a property defined in ViewModel as:
public Brush Background
{
get { return _background; }
set
{
this._background = value;
RaisePropertyChanged("Background");
}
}
And it is accessed in XAML as:
<Border Background="{Binding Background}">
<Border.Style>
<Style TargetType="{x:Type Border}">
<Style.Triggers>
<DataTrigger Binding="{Binding Background}" Value="Red">
<Setter Property="Height" Value="40"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
</Border>
The border is properly colored- no issues there.
The problem is DataTrigger is never triggered because when I see the value of this._background in set method, it is "#FFFF0000" and it is not equal to Brushes.Red (i tried converting value to SolidColorBrush and then compared with Brushes.Red, but it is not equal).
What is that I am doing wrong? What can I do to ensure that the color names that I read from a file are properly converted into Brushes.* so that my DataTrigger works fine.
Thanks,
RDV