c# - Set focus inside DataGrid -
this question looks simple, cant find answer that. have datagrid data loaded. need set focus in first row of grid. i call method button onclick event. the mygrid.focus() not focuses rows inside grid. it 1 of hardest job in wpf, , reason because of virtualization , fact ui render thread different thread runs our code (you can not find when ui render finished). complete reference can have here http://social.technet.microsoft.com/wiki/contents/articles/21202.wpf-programmatically-selecting-and-focusing-a-row-or-cell-in-a-datagrid.aspx using dispatcher.invoke might works situations (believe me in wpf dispatcher.invoke best friend , biggest enemy) dggrid.itemssource = new list<object>() { new { = 10, j = 20 }, new { = 10, j = 20 }, new { = 10, j = 20 }, new { = 10, j = 20 }, new { = 10, j = 20 } }; dispatcher.invoke(new action(delegate() { grd.selectedindex = 0; grd.focus(); } ), system.windows.threading.dispatc...