In this article we will see how to edit the selected row details in ContextMenu.
IntroductionIn my previous article on "Hide/Un-Hide Columns Using Context menu In DataGrid In WPF", we saw how we can display ContextMenu on Column Headers. In this article we will try something else; we will edit the Selected Row Details in ContextMenu.Creating WPF Application ProjectFire up Visual Studio 2008 and Create a WPF Application and name the project as EditInContextMenuInDGWPF. We need to load sample data into the DataGrid. Create a list of data based on above entity and bind it to the DataGrid in the Constructor of the Window. Now run the application to see the DataGrid with full of Data. Here's is the steps we will follow. First we need to handle the SelectionChanged event for DataGrid to generate the ContextMenu.Add the Handler in the Constructor. Then in the event add the following code to generate the ContextMenu. Now in the Button Click event we will save data. Remember in this sample I am saving the List, in real time you can change based on your datasource.Add the following code into Button Click event that we have just added in the above event. Now we have to handle the MouseRightButtonUp of DataGrid to display the ContextMenu. That's it we are done. Now run the application. Now Change some detail and click on Save Button. See the saved data. Hope this article helps.
WPF Simplified: Build Windows Apps Using C# and XAML