I have a data grid (using a datagrid template with textboxes as the cells) in a WPF MVVM application that is bound to a collection of objects. The data grid is simple, only has 2 columns ("Name" and "Year"). The window has a Input button that once clicked, inserts a blank row at the beginning of the collection and thus the beginning of the data grid.
XAML
<Button Name="InsertButton" Command="{Binding InsertCommand}" />
ViewModel
public ViewModel()
{
InsertCommand = new DelegateCommand(OnInsert);
}
private void OnInsert(object obj)
{
MyList.Insert(0, new MyItem());
}
This works with an MVVM setup, but it wondering if there is a way to set focus the first cell's textbox each time the insert button is clicked, and to program it in the XAML code behind instead of using MVVM?
Thanks