I am still a little new to wpf and MVVM. I am trying to code a solution without breaking that pattern. I have two (well three, but for the scope of this question just two) DataGrid
s. I want to double click on the row of one, and from that load data Into the second DataGrid
(ideally I would spin up a second thread that would load the data). So far I can get a window to pop up when I double click on a row. I throw the code for the event into the code behind for the xaml. To me that seems very windows formish. Somehow or the other I feel like that breaks the pattern a great deal.
private void DataGrid_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) {
if (popDataGrid.SelectedItem == null) {
return;
}
var selectedPopulation = popDataGrid.SelectedItem as PopulationModel;
MessageBox.Show(string.Format("The Population you double clicked on has this ID - {0}, Name - {1}, and Description {2}", selectedPopulation.populationID, selectedPopulation.PopName, selectedPopulation.description));
}
That is the code for the event in the code behind and here is the grids definition in the xaml:
<DataGrid ItemsSource="{Binding PopulationCollection}" Name="popDataGrid"
AutoGenerateColumns="False" RowDetailsVisibilityMode="VisibleWhenSelected"
CanUserAddRows="False" Margin="296,120,0,587" HorizontalAlignment="Left" Width="503" Grid.Column="1"
MouseDoubleClick="DataGrid_MouseDoubleClick">
</DataGrid>
I am thinking this code should go in the MainWindowViewModel. So I am attempting to create a command:
public ICommand DoubleClickPopRow { get { return new DelegateCommand(OnDoubleClickPopRow); }}
and the same event handler:
private void OnDoubleClickPopRow(object sender, MouseButtonEventArgs e) {
}
But the ICommand
is throwing an exception when it returns the DelegateCommand(OnDoubleClickPopRow)
.
Well, one can plainly see that the number of arguments doesn't match. I know I am doing something wrong, but I am not quite sure what it is. I will continue to research this but any help you guys can give would be greatly appreciated.