How to set the row back ground of a data grid programmatically
-
10 Ağustos 2012 Cuma 18:01
Hi all,
How I can set the selected row background of a datagrid in wpf.
Regards
Iqbal
itismeiqbal
- Değiştirilmiş Tür Sheldon _XiaoModerator 13 Ağustos 2012 Pazartesi 07:26
Tüm Yanıtlar
-
10 Ağustos 2012 Cuma 18:29
<DataGrid.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FF0000"/>
</DataGrid.Resources>
Source: http://stackoverflow.com/questions/1223280/how-can-i-set-the-color-of-a-selected-row-in-datagrid
-
10 Ağustos 2012 Cuma 18:33
if I want to make the color of a particular row ie the row with index 10 to red . how to do it
itismeiqbal
-
10 Ağustos 2012 Cuma 19:12
Hello,
Try this.
public MainWindow() { InitializeComponent(); myGrid.ItemContainerGenerator.StatusChanged += new EventHandler(ItemContainerGenerator_StatusChanged); } void ItemContainerGenerator_StatusChanged(object sender, EventArgs e) { var generator = sender as ItemContainerGenerator; if (generator.Status == System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated) (generator.ContainerFromIndex(0) as DataGridRow).Background = new SolidColorBrush(Colors.Red); }
Regards.
- Yanıt Olarak İşaretleyen Sheldon _XiaoModerator 13 Ağustos 2012 Pazartesi 07:26
-
10 Ağustos 2012 Cuma 20:32
if I want to make the color of a particular row ie the row with index 10 to red . how to do it
itismeiqbal
You could simplify it a bit if you're looking for a particular index...
~Christineprivate void colorRow(object sender, System.Windows.RoutedEventArgs e) { var row = myDataGrid.ItemContainerGenerator.ContainerFromIndex(10) as DataGridRow; row.Background = new SolidColorBrush(Colors.Red);
}
- Yanıt Olarak İşaretleyen Sheldon _XiaoModerator 13 Ağustos 2012 Pazartesi 07:26
-
12 Ağustos 2012 Pazar 04:05Thanks it worked fine
itismeiqbal