Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I want to use MVVM and InvokeCommandAction to trigger some DataGrid-edit-events and so to call background commands which have just to do some calculations with the changed value in the DataGrid. So I want the view to update normally as it would do without the EventTriggers. However it appears that the view does not update automatically when using these Triggers. So I wanted to know if there is a way to get the view automatically updated or at least some nice ideas how to implement the update manually?

Below some snippets of my XAML code:

XML
<DataGrid Name="dgObstructionsBottom"  CanUserAddRows="True" ItemsSource="{Binding ObstructionBottom}" Height="419" AutoGenerateColumns="False"    CurrentCell="{Binding ObstructionBottomSelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                                    
                                    <DataGrid.Columns>
                                        <DataGridTextColumn Binding="{Binding start, UpdateSourceTrigger=PropertyChanged}" Header="x1" Width="*"  EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}" />
                                        
                                        <DataGridTextColumn  Binding="{Binding end, UpdateSourceTrigger=PropertyChanged}"   Header="x2" Width="*" EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}"/>
                                    </DataGrid.Columns>
                                    <i:Interaction.Triggers>
                                        <i:EventTrigger EventName="BeginningEdit">
                                            <i:InvokeCommandAction Command="{Binding BeginningEditCommand}" CommandParameter="Bot" />
                                        </i:EventTrigger>
                                        <i:EventTrigger EventName="CellEditEnding">
                                            <i:InvokeCommandAction Command="{Binding ObstructionBottomChangeCommand}" />
                                        </i:EventTrigger>
                                        <i:EventTrigger EventName="AddingNewItem">
                                            <i:InvokeCommandAction Command="{Binding AddingNewItemCommand}"/>
                                        </i:EventTrigger>
                                    </i:Interaction.Triggers>
                                    <DataGrid.InputBindings>
                                        <KeyBinding Key="Delete" Command="{Binding ObstructionBottomRemoveCommand}"/>
                                    </DataGrid.InputBindings>
                                </DataGrid>


What I have tried:

So i somehow managed to do it manually but therefore I have to save an old version of the Datagrids ItemsSource and to check where i have to insert the changes.
Posted
Comments
[no name] 10-Feb-20 7:55am    
You don't update the "grid", you update the data source; and if you use an "Observable Collection", all this is handled for you.
joni7373 10-Feb-20 8:03am    
In fact I use an Observable Collection as ItemsSource and without the Eventtrigger everything is handled automatically, but not when I use the trigger.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900