I have a datagrid which is bound to a collection on my ViewModel. When the window loads the datagrid is populated and the SelectedItem is set. (I know this because I have a detail view bound to the selected item.) The row however is not highlighted. If I click on the row then it will be highlighted and works normally.
How do I make the selected row appear highlighted when its the default selection?
<DataGrid IsSynchronizedWithCurrentItem="True" SelectionUnit="FullRow" RowHeaderWidth="0" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible" IsReadOnly="True" ItemsSource="{Binding Items}" SelectedItem="{Binding Path=SelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Run Date" Binding="{Binding Path=RunDate, StringFormat={}{0:MM-dd-yy HH:mm:ss} }" />
<DataGridTextColumn Header="Description" Binding="{Binding Description}" />
<DataGridTextColumn Header="Duration" Binding="{Binding Duration}" />
<DataGridTextColumn Header="Deviation" Binding="{Binding Deviation}" />
</DataGrid.Columns>
</DataGrid>
DataGrid. As far as I know, theDataGriddoes not highlight the selected row, if the Grid itself or one of its childs is not focused. - HerdoSelectedItemproperty of theDataGrid, it should be at least highlighted in light-grey. Once you need to have to highlighted in blue, you should reconsider the way to update theSelectedItemproperty of your viewmodel. You might want to set theSelectedItemand the focus to theUIElementfrom the same method. - Herdo