Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF focus row of datagrid with only XAML

I can set the focus with only XAML to a Datagrid.
It eludes me how (if possible at all) how to set focus to the first row with only XAML.

My (shortened) XAML:

<Window x:Class="WhatIsInTheBarnBooth.MainWindow"
    ...
    FocusManager.FocusedElement="{Binding ElementName=grdData}">
</Window>

<DataGrid Name="grdData">
    ...
</DataGrid>
like image 881
LosManos Avatar asked Dec 08 '25 07:12

LosManos


1 Answers

Can you try....

FocusManager.FocusedElement="{Binding ElementName=myDataGrid}"

and

<DataGrid Name="grdData" SelectedIndex="0">
    ...
</DataGrid>
like image 81
Rohit Avatar answered Dec 10 '25 20:12

Rohit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!