Change DataGrid cell state with DataStateSwitchBehavior issue

Oct 19, 2009 at 8:49 AM


I am trying to use DataStateSwitchBehavior for animating Datagrid cells based on the viewmodel the datagrid is attached to. My goal is to change the color of the value in the grid cell when the price property of my viewmodel changes. (price went down->red, price went up->green, price did not change->default color)
So far I did the followings:
1. I defined PriceChange enum for these 3 states
2. In my viewmodel, when the Price property changes, I also set the MarketChangeDirection property (of type PriceChange) accordingly. This property is bound to the DataStateSwitchBehavior
3. I use DataGridTemplateColumn for the Price column (bound to the Price property of VM) where I use a textblock (inside the datatemplate)to show the price.

My problems are:
1. I am not sure where I should place the DataStateSwitchBehavior (inside the datatemplate? or inside the datagrid?)
2. Should I change the default cellstyle for the Price column and define my 3 states+storyboards in the new controltemplate of the DataGridCell? If yes, which part of the DataGridCell can I animate (I can only see 2 Rectangles named RightGridLine and FocusVisual, a ContentPresenter (without name), and the Root grid in the default controltemplate)
3. Can the DataStateSwitchBehavior reach states in the controltemplate of the datagrid? Or should I define them inside the datagrid element?
4. Is it possible to debug the behavior (to see how the storyboard is actually started when the state changes)

Right now I am using ValueConverter to solve this issue. But this solution lacks animations.

I would really appreciate if anyone can help on this.

Thanks, Adam