I have a little problem about selecting all rows from a DataGrid. The question is that the CommandButton is in a UserControl which refers to the MainViewModel and the grid is in a UserControl which refers to another ViewModel. The first thought was to make a static method and call it from the mvm, but the datagrid is not static and can't be called. How can i do?
Edit:
I actually solved the problem by rferencing a static instance of the grid from the code behind.
In the pushbutton viewmodel i recalled the select all method inside the command execution
if (_CommandBtnSelectAll == null)
{
// creo una nuova istanza del comando
_CommandBtnSelectAll = new USCommands(
item =>
{
ViewControlCodeBehind.grid.SelectAll();
}
}
In the ViewControl Code Behind i just had to set a static instance of a new DataGrid and assign it the actual datagrid.
public static DataGrid grid;
public ControlBody() // It's the UserControl initialization
{
this.grid = DataGridControl; // DataGridControl is the name of the actual control
}