I want to load window in Datagrid 5 row selected
My code, but color does not change
DataGridRow row = (DataGridRow)DataGridService.ItemContainerGenerator.ContainerFromIndex(5);
object item = DataGridService.Items[5];
DataGridService.SelectedItem = item;
DataGridService.ScrollIntoView(item);
row.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
Xaml
<DataGrid.Resources>
<SolidColorBrush x:Key="SelectionColorKey" Color="Red"/>
<Style TargetType="DataGridRow">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="{Binding Source={StaticResource SelectionColorKey}, Path=Color}"/>
</Style.Resources>
</Style>
</DataGrid.Resources>
May be i not correct formulated problem. I need on load window, background row 5 was red color and focus was in 5 row
It does not work
DataGridService.SelectedItem = DataGridService.Items[5];
strangely in Winforms this makes easy
How selected first row?
Why is the problem with selected color?
DataGridCell. So each cell can change it's bachgroundcolor if it is selected - Tomtom