2011-10-07 57 views
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?

回答

0

一個MultiDataTrigger就像使用一個AND聲明與觸發器,所以你基本上是說,如果Tag等於RedWhiteBlackBlueGreen,然後應用下面的樣式,但是標籤只能等於到這些值中的一個,所以觸發器總是以False結尾。

具有多個觸發器,例如您的工作代碼,是我使用的語法,如果我想要觸發器OR

+0

啊好吧。我明白。是否可以在XAML中使用OR命令? –

+0

據我所知,我必須使用轉換器才能做到這一點 –

+0

因爲您可以使用多個DataTrigger,所以不需要「OR」條件。 –

相關問題