Я не думаю, что это относится к ItemContainerStyle, поскольку управление элементами находится на более высоком уровне самого ListView.
Один из способов добиться этого - использовать поведение из Blend SDK, например:
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
<ListView ItemsSource="{Binding DpData}">
<i:Interaction.Behaviors>
<b:FlashNewRowBehavior />
</i:Interaction.Behaviors>
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Name}" />
<GridViewColumn DisplayMemberBinding="{Binding Occupation}" />
</GridView>
</ListView.View>
</ListView>
class FlashNewRowBehavior : Behavior<ListView>
{
protected override void OnAttached()
{
base.OnAttached();
AssociatedObject.Loaded += new System.Windows.RoutedEventHandler(AssociatedObject_Loaded);
}
void AssociatedObject_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
var itemsSource = AssociatedObject.ItemsSource;
if (itemsSource is INotifyCollectionChanged)
{
var collection = itemsSource as INotifyCollectionChanged;
collection.CollectionChanged += (s, cce) =>
{
if (cce.Action == NotifyCollectionChangedAction.Add)
{
// This code sadly is rather unclean, some wait is necessary or the ItemContainerGenerator will return null
Wait(TimeSpan.FromSeconds(0.01));
var itemContainer = AssociatedObject.ItemContainerGenerator.ContainerFromItem(cce.NewItems[0]) as ListViewItem;
if (itemContainer != null)
{
Storyboard sb = new Storyboard();
ColorAnimation anim = new ColorAnimation()
{
// From is not really needed (if you want to animate from the current background color at least)
From = Colors.Navy,
// I would create properties instead of hardcoded values
To = Colors.White,
Duration = (Duration)TimeSpan.FromSeconds(0.4),
AutoReverse = true
};
Storyboard.SetTargetProperty(anim, new PropertyPath("Background.Color"));
Storyboard.SetTarget(anim, itemContainer);
sb.Children.Add(anim);
sb.Begin();
}
}
};
}
}
private static void Wait(TimeSpan timeout)
{
var frame = new DispatcherFrame();
new Thread((ThreadStart)(() =>
{
Thread.Sleep(timeout);
frame.Continue = false;
})).Start();
Dispatcher.PushFrame(frame);
}
}