本文介绍了Multidatatrigger与datatrigger.为什么我的多数据触发器不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么这行不通:

I cannot figure out why 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>
</resourcedictionary>




当此方法有效时:




When 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>
</resourcedictionary>

推荐答案


这篇关于Multidatatrigger与datatrigger.为什么我的多数据触发器不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 07:27