I have two tabitems. User will enter some data and save it on the first tab. The second tab lists the saved data. What I need is when the user select the second tab before saving data in first tab a confirmation message box with Yes, No and Cancel should be shown. If the user clicks Yes button the data should be saved and go to the second tab. If he hits No, the data need not to be saved and finally if Cancel is hit the tab will retain with all entered data. How can i make this?
Share
To keep things simple you can do the follwing in the Code Behind file.
I’d create a Model class of the data you want to display and edit in the WPF Control. Make the Model implement the
INotifyPropertyChangedandIEditableObjectinterfaces.INotifyPropertyChangedwill allow you to Bind to the Model.IEditableObjectwill allow you to provide Edit, Save and Cancel functionality.The TabControl has a
SelectionChangedEvent you can handle, that will allow you to detect when the user changes tabs, in this handler you can useSystem.Windows.MessageBoxto ask the user to save etc,System.Windows.MessageBox.Show()returns aMessageBoxResultObject you can use to detirmine what button the user clicked and perform the appropiate action.This is not a geat way to do things, but it keeps things simple, you may want to look into some WPF design Patterns to help with Code Manageability.
If you need anything explained further, just ask.