-
August 22nd, 2011, 05:24 AM
#1
Flashing DataGrid Cell - How to do it properly
Hi,
I am developing an application that requires showing data in a datagrid and having a "flashing" animation when the value of a cell changes.
My (business object) class implements the INotifyPropertyChanged interface. I have a list of that class (via ListCollectionView)
I've figured out a way to do it using DataGridTemplateColumn and a DataTemplate:
In Window.Resources:
<DataTemplate x:Key="FlashingCellMyProperty">
<TextBlock Name="TextBlockValue" Text="{Binding lMyProperty, Mode=OneWay,NotifyOnTargetUpdated=True}">
<TextBlock.Background>
<SolidColorBrush x:Name="bgBrush" />
</TextBlock.Background>
<TextBlock.Triggers>
<EventTrigger SourceName="TextBlockValue" RoutedEvent="Binding.TargetUpdated">
<BeginStoryboard HandoffBehavior="Compose">
<Storyboard>
<ColorAnimation Duration="0:0:0.03" Storyboard.TargetName="bgBrush" Storyboard.TargetProperty="Color" To="Red" AutoReverse="True"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</TextBlock.Triggers>
</TextBlock>
</DataTemplate>
Then later in my window I have a grid that contains the DataGrid:
<DataGrid AutoGenerateColumns="False" Name="dataGrid1" ItemsSource="{Binding MyList}">
<DataGrid.Columns>
<DataGridTextColumn Header="Strike" Binding="{Binding ExpirationPrice}"/>
<DataGridTemplateColumn Header="My Property" CellTemplate="{StaticResource FlashingCellMyProperty}"/>
</DataGrid.Columns>
</DataGrid>
This works fine but it seem to me a little wasteful to have a data template for each property. Optimally I'd like to have a way to define a "style" or a control template or somehow change existing "stock" column (e.g. DataGridTextColumn) and only change the binding on each column.
I've search a lot online but didn't find the right path to follow. I am new to WPF and trying to read but there's much to read and I am not sure what subject I need to learn.
Thanks!
Last edited by tomercagan; August 22nd, 2011 at 06:28 AM.
Reason: Mistake in ItemSource used
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|