开发者

Works with XAML Datatrigger, but not with XAMl MultiDataTrigger.

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_BackgroundColo开发者_运维百科r, 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 MultiDataTrigger is like using an AND statement with your Triggers, so you are basically saying if the Tag is equal to Red, White, Black, Blue, and Green, 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 OR the triggers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜