积极答复者
wpf toolkit datagrid如何设置背景色?

问题
-
RT
我想在程序中设置某一行的背景色,怎么搞?
无
- 已移动 ThankfulHeart 2012年10月30日 8:41 WPF问题 (发件人:.NET Framework 一般性问题讨论区)
答案
-
你可以得到你的DataGridRow,然后改变,比如在loadingrow 事件里面:
private void DataGrid_LoadingRow(object sender, System.Windows.Controls.DataGridRowEventArgs e) { Persons RowDataContaxt = e.Row.DataContext as Persons; if (RowDataContaxt != null) { if (RowDataContaxt.Sales == 50) e.Row.Background = FindResource("RedBackgroundBrush") as Brush; else if (RowDataContaxt.Sales == 60) e.Row.Background = FindResource("GreenBackgroundBrush") as Brush; } }
或者在xaml里面用style:
<Style.Triggers> <DataTrigger Binding="{Binding Sales}" Value="90"> <Setter Property="Background" Value="{StaticResource RedBackgroundBrush}"/> </DataTrigger> <DataTrigger Binding="{Binding Sales}" Value="80"> <Setter Property="Background" Value="{StaticResource GreenBackgroundBrush}"/> </DataTrigger> </Style.Triggers>
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Sheldon _XiaoModerator 2012年11月6日 8:20
全部回复
-
你可以得到你的DataGridRow,然后改变,比如在loadingrow 事件里面:
private void DataGrid_LoadingRow(object sender, System.Windows.Controls.DataGridRowEventArgs e) { Persons RowDataContaxt = e.Row.DataContext as Persons; if (RowDataContaxt != null) { if (RowDataContaxt.Sales == 50) e.Row.Background = FindResource("RedBackgroundBrush") as Brush; else if (RowDataContaxt.Sales == 60) e.Row.Background = FindResource("GreenBackgroundBrush") as Brush; } }
或者在xaml里面用style:
<Style.Triggers> <DataTrigger Binding="{Binding Sales}" Value="90"> <Setter Property="Background" Value="{StaticResource RedBackgroundBrush}"/> </DataTrigger> <DataTrigger Binding="{Binding Sales}" Value="80"> <Setter Property="Background" Value="{StaticResource GreenBackgroundBrush}"/> </DataTrigger> </Style.Triggers>
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Sheldon _XiaoModerator 2012年11月6日 8:20