When using Normal trigger I can get the functionality to work easily.
But when I use MultiDataTrigger I cannot get it to work.
This does not work.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="Brush_GridBackground" TargetType="{x:Type Grid}">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ElementName=cb_BackgroundColor, Path=SelectedItem.Tag}" Value="Red" />
<Condition Binding="{Binding ElementName=cb_BackgroundColor, Path=SelectedItem.Tag}" Value="White" />
<Condition Binding="{Binding ElementName=cb_BackgroundColor, Path=SelectedItem.Tag}" Value="Black" />
<Condition Binding="{Binding ElementName=cb_BackgroundColor, Path=SelectedItem.Tag}" Value="Blue" />
<Condition Binding="{Binding ElementName=cb_BackgroundColor, Path=SelectedItem.Tag}" Value="Green" />
</MultiDataTrigger.Conditions>
<Setter Property="Background" Value="{Binding ElementName=cb_BackgroundColor, Path=SelectedItem.Tag}" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
This works
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="Brush_GridBackground" TargetType="{x:Type Grid}">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=cb_BackgroundColor, Path=SelectedItem.Tag}" Value="Red">
<Setter Property="Background" Value="{Binding ElementName=cb_BackgroundColor, Path=SelectedItem.Tag}" />
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=cb_BackgroundColor, Path=SelectedItem.Tag}" Value="White">
<Setter Property="Background" Value="{Binding ElementName=cb_BackgroundColor, Path=SelectedItem.Tag}" />
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=cb_BackgroundColor, Path=SelectedItem.Tag}" Value="Black">
<Setter Property="Background" Value="{Binding ElementName=cb_BackgroundColor, Path=SelectedItem.Tag}" />
</DataTrigger>
</Style.Triggers>
</Style>
Howcome?
A
MultiDataTriggeris like using anANDstatement with your Triggers, so you are basically saying if theTagis equal toRed,White,Black,Blue, andGreen, then apply the following style, however the tag can only equal to one of those values, so the trigger is always going to end up as False.Having Multiple triggers, such as your working code, is the syntax I use if I want to
ORthe triggers.