Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit DataGrid: How to set different row backgound for different rows from viewModel
2 replies. Latest Post by yifung on November 6, 2009.
(0)
kobruleht
Member
161 points
579 Posts
11-05-2009 4:15 PM |
I'm looking for a way to use viewmodel to set DataGrid RowBackGround based on this row property values.
I tried code below but viewModel RowBackGround property getter is called only once. How to force RowBackGround getter in viewModel called for every row ?
Andrus.
<UserControl.Resources> <content:VirtualGridFormModel x:Key="viewModel" /> </UserControl.Resources>
<Grid DataContext="{StaticResource viewModel}">
<DataGrid RowBackground="{Binding Path=RowBackground, Mode=TwoWay}" />>
public class VirtualGridFormModel: INotifyPropertyChanged { public Brush RowBackground { get {
....
Sergey.L...
Contributor
7198 points
1,340 Posts
11-05-2009 6:42 PM |
Hi Andrus,
You can't do that from xaml code. Use LoadingRow event of DataGrid and set background of row in handler
yifung
3313 points
540 Posts
11-06-2009 8:20 PM |
If you re-template the DataGridRow, you can also binding the background to your view model using a converter that returns a brush when given a value.