Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Datagrid RowEditEnding in an MVVM environment

I've been trying to capture the values that a user enters into a datagrid by using

<b:Interaction.Triggers>
    <b:EventTrigger EventName="RowEditEnding">
        <b:InvokeCommandAction  Command="{Binding ReleaseRowEditEndingCommand}" CommandParameter="{Binding SelectedRelease}"/>
    </b:EventTrigger>

But this doesn't work and I now understand this afte reading this article on StackOverflow. The solutions presented all seem to be based on directly calling a method signature that matches the event being raised, in this case

private void OnRowEditEnding(object sender, DataGridRowEditEndingEventArgs e)

Has anyone accomplished getting the values post-rowedit in an MVVM situation? All the solutions seem to tightly bind the event to the XAML and I'd like to avoid that, if possible.

like image 631
Josh Avatar asked Sep 06 '11 21:09

Josh


1 Answers

The solution was actually easier than I thought. I changed the XAML and I can now get the values in the RowEditEnding event on the View Model. Here's the before on the data columns on the datagrid:

 <DataGrid.Columns>
    <DataGridCheckBoxColumn Header="Is Paid" Binding="{Binding IsPaid, Mode=TwoWay}" />
    <DataGridTextColumn Header="Amount" Binding="{Binding Amount, Mode=TwoWay}" />
</DataGrid.Columns>

After

 <DataGrid.Columns>
    <DataGridCheckBoxColumn Header="Is Paid" Binding="{Binding IsPaid, UpdateSourceTrigger=PropertyChanged}" />
    <DataGridTextColumn Header="Amount" Binding="{Binding Amount,  UpdateSourceTrigger=PropertyChanged}" />
</DataGrid.Columns>
like image 101
Josh Avatar answered Oct 14 '22 20:10

Josh