0
當使用正常觸發器時,我可以輕鬆地實現功能。 但是,當我使用MultiDataTrigger我不能得到它的工作。適用於XAML Datatrigger,但不適用於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_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>
Howcome?
啊好吧。我明白。是否可以在XAML中使用OR命令? –
據我所知,我必須使用轉換器才能做到這一點 –
因爲您可以使用多個DataTrigger,所以不需要「OR」條件。 –