Wpf 适用于XAML Datatrigger,但不适用于XAML MultiDataTrigger。

Wpf 适用于XAML Datatrigger,但不适用于XAML MultiDataTrigger。,wpf,xaml,Wpf,Xaml,当使用普通触发器时,我可以轻松获得功能。 但是当我使用MultiDataTrigger时,我无法让它工作 这是行不通的 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Style x:Key="Brush_Gri

当使用普通触发器时,我可以轻松获得功能。 但是当我使用MultiDataTrigger时,我无法让它工作

这是行不通的

<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 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>


怎么样?

一个
多数据触发器
就像在触发器中使用一个
语句,所以你基本上是说如果
标记
等于
红色
白色
黑色
蓝色
,和
绿色
,然后应用以下样式,但是,标记只能等于这些值中的一个,因此触发器总是以False结束


如果我想
触发器,我使用的语法就是有多个触发器,比如你的工作代码。

Ahh好的。我理解。是否可以在XAML中使用或使用命令?据我所知,我必须使用转换器来执行此操作。不需要使用
条件,因为您可以使用多个数据触发器。