Note that there are some explanatory texts on larger screens.

plurals
  1. POPopulate a second DataGrid once I double click on a row WPF
    text
    copied!<p>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) <code>DataGrid</code>s. I want to double click on the row of one, and from that load data Into the second <code>DataGrid</code> (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. </p> <pre><code>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)); } </code></pre> <p>That is the code for the event in the code behind and here is the grids definition in the xaml:</p> <pre><code>&lt;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"&gt; &lt;/DataGrid&gt; </code></pre> <p>I am thinking this code should go in the MainWindowViewModel. So I am attempting to create a command:</p> <pre><code>public ICommand DoubleClickPopRow { get { return new DelegateCommand(OnDoubleClickPopRow); }} </code></pre> <p>and the same event handler:</p> <pre><code>private void OnDoubleClickPopRow(object sender, MouseButtonEventArgs e) { } </code></pre> <p>But the <code>ICommand</code> is throwing an exception when it returns the <code>DelegateCommand(OnDoubleClickPopRow)</code>.</p> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload