2014-03-25 96 views
1

我有這勢必以下類型的項目的List一個ListView如何在ListBox中閃爍項目時屬性更改

class Item : INotifyPropertyChanged 
{ 
    //Both these props have property change notification implemented. Left out for brevity. 
    int Price{get;set} 
    int Size{get;set} 
} 

我有一個DataTemplate這個類中ListView

展示

列表大小不會更改,但列表中項目的屬性的值會更改。假設我首先得三個項目是這樣的:

Item format : [email protected] 

{([email protected]), ([email protected]), ([email protected])} 

現在假設第一個項目只更改由於數據更新:

{([email protected]), ([email protected]), ([email protected])} 

請注意,我不刪除現有項目。我只改變它的屬性。因此,每次更改都會觸發屬性更改通知。我想突出顯示/閃爍在ListView更改的項目。我該如何做(最好在XAML中)?

回答

0

不知道我按照這個權利,你只是想說閃ListViewItemSizePrice屬性更改?

如果是這樣,您應該可以使用Binding.TargetUpdated事件觸發器來做到這一點。您確實需要確保您的綁定中綁定的SizePrice也指定NotifyOnTargetUpdated=True來觸發此事件。

所以這樣的事情應該很好地工作:

<DataTemplate x:Key="SomeTemplate" DataType="viewModel:Item"> 
    <StackPanel x:Name="stackPanel" 
       Background="Transparent" 
       Orientation="Vertical"> 
    <!-- This prolly aint your layout. Just here as an example --> 
    <TextBlock Text="{Binding Size, NotifyOnTargetUpdated=True}" /> 
    <TextBlock Text="{Binding Price, NotifyOnTargetUpdated=True}" /> 
    </StackPanel> 
    <DataTemplate.Triggers> 
    <EventTrigger RoutedEvent="Binding.TargetUpdated"> 
     <BeginStoryboard> 
     <Storyboard AutoReverse="True"> 
      <!-- From="1.0" helps prevent spam property changes skewing the opacity --> 
      <DoubleAnimation Duration="0:0:0.3" 
          Storyboard.TargetName="stackPanel" 
          Storyboard.TargetProperty="Opacity" 
          From="1.0" 
          To="0.3" /> 
     </Storyboard> 
     </BeginStoryboard> 
    </EventTrigger> 
    </DataTemplate.Triggers> 
</DataTemplate> 

備選:

從交融xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" 你也應該使用<ei:PropertyChangedTrigger>,然後你可以說調用行爲觸發Storyboard<ei:ControlStoryboardAction>。我個人只使用第一種方法,因爲它稍微簡單一些。

+0

我會試試這個!謝謝。 – nakiya

+0

@nakiya你真的嘗試過嗎? – Viv

相關問題