Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I cannot figure out why this does not work:
HTML
<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>
</resourcedictionary>



When this works:
HTML
<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>
</resourcedictionary>
Posted

1 solution

The conditions in your MultiDataTrigger are and'ed together thus all has to be true, which is not possible in the posted example.
While in the DataTrigger example all the DataTrigger's gets evaluated and any that is true gets to set values.

So multiple triggers are or'ed together, if they set the save value the last one on the list gets it's way. And the type of trigger called MultiDataTrigger/MultiTrigger has a collection of conditions which must all be evaluated to true for the trigger to set any value(s).
 
Share this answer
 
Comments
Espen Harlinn 8-Oct-11 7:00am    
You definitely know your way around WPF, Simon :)
Simon Bang Terkildsen 8-Oct-11 11:59am    
Thank you, Espen. WPF is a passion of mine :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900