2011-03-02 77 views
1

我有AlternationCount設置爲2。我目前設定的ListViewItem的背景色交替的顏色ListViewItem的風格的ListView,我想補充一個不觸發這將觸發ColorAnimation第三觸發動畫紅色和白色的顏色,當綁定視圖模型的屬性爲true(在這種情況下,所謂的財產「鎖定」)。ColorAnimation在MultiDataTrigger的EnterActions當項目被添加到ListView控件

我遇到了這個帖子,並試圖在XAML底部:

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e7897cbd-71d9-45e6-9b17-0cd5bde5859f

但是,動畫不會出現過度觸發我,直到我的鼠標或選擇項目,然後選擇或將鼠標懸停在不同的項目上。我從前兩個MultiDataTriggers中獲取交替的顏色,但是當項目添加到集合中時不會觸發動畫。這是我的XAML:

<Style x:Key="alternatingListViewItemStyle" TargetType="{x:Type ListViewItem}"> 
     <Setter Property="Background" Value="White" /> 
     <Style.Triggers> 
      <MultiDataTrigger > 
       <MultiDataTrigger.Conditions> 
        <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(ItemsControl.AlternationIndex)}" Value="0" /> 
        <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(ListViewItem.IsSelected)}" Value="False" /> 
        <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Panel.IsMouseOver)}" Value="False" /> 
        <Condition Binding="{Binding Locked}" Value="False" /> 
       </MultiDataTrigger.Conditions> 
       <Setter Property="Background" Value="DarkGray" /> 
       </MultiDataTrigger> 
      <MultiDataTrigger > 
       <MultiDataTrigger.Conditions> 
        <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(ItemsControl.AlternationIndex)}" Value="1" /> 
        <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(ListViewItem.IsSelected)}" Value="False" /> 
        <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Panel.IsMouseOver)}" Value="False" /> 
        <Condition Binding="{Binding Locked}" Value="False" /> 
       </MultiDataTrigger.Conditions> 
       <Setter Property="Background" Value="SlateGray" /> 
       </MultiDataTrigger> 
      <MultiDataTrigger> 
       <MultiDataTrigger.Conditions> 
        <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(ListViewItem.IsSelected)}" 
             Value="False" /> 
        <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Panel.IsMouseOver)}" 
             Value="False" /> 
        <Condition Binding="{Binding Locked}" 
             Value="True" /> 
       </MultiDataTrigger.Conditions> 
       <MultiDataTrigger.EnterActions> 
        <BeginStoryboard> 
         <Storyboard> 
          <ColorAnimation 
           Storyboard.TargetProperty="(Control.Background).(SolidColorBrush.Color)" 
           From="Red" To="White" Duration="0:0:0.2" 
           AutoReverse="True" RepeatBehavior="Forever" /> 
         </Storyboard> 
        </BeginStoryboard> 
       </MultiDataTrigger.EnterActions> 
      </MultiDataTrigger> 
     </Style.Triggers> 
    </Style> 

回答

2

我沒有特定的語法爲您的例子,但你可以嘗試直接把觸發器上ListView控件(不是資源),並使用ListView.ItemContainerStyle而非SYLE。我無法在Resouces中使下面的簡單代碼工作,但是當我直接將它移動到它工作的ListView時。我在資源時可能有語法錯誤,例如

<ListView AlternationCount="2" 
       ItemsSource="{Binding Path=...}"> 
     <ListView.ItemContainerStyle> 
      <Style TargetType="ListViewItem"> 
       <Style.Triggers> 
        <!-- setting up triggers for alternate background colors --> 
        <Trigger Property="ItemsControl.AlternationIndex" Value="1"> 
         <Setter Property="Background" Value="Gainsboro"></Setter> 
        </Trigger> 
        <Trigger Property="ItemsControl.AlternationIndex" Value="2"> 
         <Setter Property="Background" Value="White"></Setter> 
        </Trigger> 
       </Style.Triggers> 
      </Style> 
     </ListView.ItemContainerStyle> 
    <ListView.View>