开发者

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 ReleaseRowEditEndingComma开发者_如何学Cnd}" 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.


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>


You could try wrapping your data in a ListCollectionView and binding the DataGrid to the ListCollectionView. Then, in your ViewModel, hook into the ListCollectionView.CurrentChanging event to process your changes before moving to the new row.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜