WPF data binding - How to cancel an edit
-
Hi, I have a WPF form for the user to edit some details of an object. Most of the fields are fairly simple text/numeric style fields. I've bound the controls to the properties on the object being edited, and everything works great. Except, how do I cancel the changes when the user hits the cancel button?
Simon
-
Hi, I have a WPF form for the user to edit some details of an object. Most of the fields are fairly simple text/numeric style fields. I've bound the controls to the properties on the object being edited, and everything works great. Except, how do I cancel the changes when the user hits the cancel button?
Simon
Simon, You have some options. 1. You can keep a copy of the object and replace the original values from the copy if the user cancels. 2. If this is a database application, just reread the record from the database. (or reread from the original source)
Cheers, Karl
My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your ArticlesJust a grain of sand on the worlds beaches.
-
Simon, You have some options. 1. You can keep a copy of the object and replace the original values from the copy if the user cancels. 2. If this is a database application, just reread the record from the database. (or reread from the original source)
Cheers, Karl
My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your ArticlesJust a grain of sand on the worlds beaches.
Thanks Karl, I was hoping there was something simpler than that. To be honest, it's easier to just go back to the old style and copy the object to the controls when the form is opened, then from the controls to the object when the user hits OK. I don't get the advantage of data binding. Am I missing something?
Simon
-
Thanks Karl, I was hoping there was something simpler than that. To be honest, it's easier to just go back to the old style and copy the object to the controls when the form is opened, then from the controls to the object when the user hits OK. I don't get the advantage of data binding. Am I missing something?
Simon
Yes I think you may be missing a number of built in features. WPF 3.5 now supports the IDataErrorInfo interface. There is plenty of info out there on WPF object data binding. I'm working on an article today that includes a notification control that is wired up to the business object. I about 2 weeks I'll also have a the 4th in my WPF Business Application series that covers "how to" do a great number of things with the data binding and business objects. Trust me, you want to try and use the WPF Data Binding. Very powerful. Bea Costa is the First Lady of WPF Data Binding. Here blog is here: http://www.beacosta.com/blog/[^]
Cheers, Karl
My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your ArticlesJust a grain of sand on the worlds beaches.
-
Yes I think you may be missing a number of built in features. WPF 3.5 now supports the IDataErrorInfo interface. There is plenty of info out there on WPF object data binding. I'm working on an article today that includes a notification control that is wired up to the business object. I about 2 weeks I'll also have a the 4th in my WPF Business Application series that covers "how to" do a great number of things with the data binding and business objects. Trust me, you want to try and use the WPF Data Binding. Very powerful. Bea Costa is the First Lady of WPF Data Binding. Here blog is here: http://www.beacosta.com/blog/[^]
Cheers, Karl
My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your ArticlesJust a grain of sand on the worlds beaches.
I'll stick with it. I'm still new to WPF, we're only using it in small internal apps at the moment. Nothing serious. I actually found something on her blog that helps with my original question http://www.beacosta.com/blog/?p=15[^]. If I set the update source trigger to explicit, and call UpdateSource() when the user hits OK, that looks like it will do what I want. I'll try it out. I'll keep a watch out for those articles, they sound useful. Thanks for the help,
Simon
-
I'll stick with it. I'm still new to WPF, we're only using it in small internal apps at the moment. Nothing serious. I actually found something on her blog that helps with my original question http://www.beacosta.com/blog/?p=15[^]. If I set the update source trigger to explicit, and call UpdateSource() when the user hits OK, that looks like it will do what I want. I'll try it out. I'll keep a watch out for those articles, they sound useful. Thanks for the help,
Simon
Simon, Glad to hear it. WPF has a learning curve, but it is worth it! :cool:
Cheers, Karl
My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your ArticlesJust a grain of sand on the worlds beaches.