I need to assign a color to the row I add at runtime to the DataTable. How can this be done?
相关问题
- VNC control for WPF application
- WPF Binding from System.Windows.SystemParameters.P
- DBGrid - How to set an individual background color
- XAML: Applying styles to nested controls
- How can I add a horizontal line (“goal line”) for
IMPORTANT : be sure to always assign defaults for rows that aren't being colored by a condition - or any other style.
See my answer to C# Silverlight Datagrid - Row Color Change.
PS. I am in Silverlight and haven't confirmed this behavior in WPF
You can handle the DataGrid's LoadingRow event to detect when a row is being added. In the event handler you can get a reference to the DataRow that was added to the DataTable that is acting as your ItemsSource. Then you can update the DataGridRow's color however you like.
To sign up for the event in XAML:
Or in C#:
U can try this
In the XAML
In the datagrid
In the code i have a class with
When set the DataContext
If u not set the color of the row the default value is Grey
u can try this sample with this sample