![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Solving an age-old problem I'm in the beginning stages of a new WPF/.NET 3.0 application. This is a re-write of an existing 1.1 application. I was hoping that WPF would offer a simple solution to a coding scenario that I've encountered on many applications prior. Basically, in the WPF version, I have UI elements that are bound to a custom class. This custom class implements the INotifyPropertyChange interface, and has many properties that are maintained by the user via the UI. The binding between the source and target are all working fine. I have a button to click in order to save the modified class via XML Serialization, and I want this button "Enabled" only when the user has modified the data AFTER it has been displayed. In past projects I've had to resort to handling the changed events for each TextBox, ComboBox, CheckBox etc, and enabling the button via code, but only if a key was pressed or a control raised the MouseUp event, or something similar. Is there something in WPF that could eliminate this tedium? |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Solving an age-old problem Hi, Michael Jackson wrote: > I'm in the beginning stages of a new WPF/.NET 3.0 application. This is a > re-write of an existing 1.1 application. I was hoping that WPF would offer a > simple solution to a coding scenario that I've encountered on many > applications prior. > > Basically, in the WPF version, I have UI elements that are bound to a custom > class. This custom class implements the INotifyPropertyChange interface, and > has many properties that are maintained by the user via the UI. The binding > between the source and target are all working fine. > > I have a button to click in order to save the modified class via XML > Serialization, and I want this button "Enabled" only when the user has > modified the data AFTER it has been displayed. > > In past projects I've had to resort to handling the changed events for each > TextBox, ComboBox, CheckBox etc, and enabling the button via code, but only > if a key was pressed or a control raised the MouseUp event, or something > similar. > > Is there something in WPF that could eliminate this tedium? Yes. Bindings in WPF can go two ways, which means that a textbox displaying a property will also update the property automatically when its content is changed. You do not need to observe the "changed" event of the textbox yourself. For the binding to go two ways, you need to specify the Mode property. Note: For a texbox, it is already two ways by default. For other controls, you'll need to check the documentation. To specifiy when the property must be updated (for example on every key press event, or only when it loses the focus), you need to specify the UpdateSourceTrigger property. You should find examples of that in MSDN. For your "Enabled" button, simply bind the IsEnabled property to a boolean property of your data object. Set this property to true when the data object has been modified. Set it to false again after the data object has been saved. Greetings, Laurent -- Laurent Bugnion [MVP ASP.NET] Software engineering, Blog: http://www.galasoft-LB.ch PhotoAlbum: http://www.galasoft-LB.ch/pictures Support children in Calcutta: http://www.calcutta-espoir.ch |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: Solving an age-old problem Take a look at : http://blogs.msdn.com/dancre/archive...-commands.aspx It offers a much cleaner solution.... "Laurent Bugnion, MVP" <galasoft-lb@bluewin.ch> wrote in message news:uNoHfKqoHHA.4428@TK2MSFTNGP06.phx.gbl... > Hi, > > Michael Jackson wrote: >> I'm in the beginning stages of a new WPF/.NET 3.0 application. This is a >> re-write of an existing 1.1 application. I was hoping that WPF would >> offer a simple solution to a coding scenario that I've encountered on >> many applications prior. >> >> Basically, in the WPF version, I have UI elements that are bound to a >> custom class. This custom class implements the INotifyPropertyChange >> interface, and has many properties that are maintained by the user via >> the UI. The binding between the source and target are all working fine. >> >> I have a button to click in order to save the modified class via XML >> Serialization, and I want this button "Enabled" only when the user has >> modified the data AFTER it has been displayed. >> >> In past projects I've had to resort to handling the changed events for >> each TextBox, ComboBox, CheckBox etc, and enabling the button via code, >> but only if a key was pressed or a control raised the MouseUp event, or >> something similar. >> >> Is there something in WPF that could eliminate this tedium? > > Yes. Bindings in WPF can go two ways, which means that a textbox > displaying a property will also update the property automatically when its > content is changed. You do not need to observe the "changed" event of the > textbox yourself. > > For the binding to go two ways, you need to specify the Mode property. > Note: For a texbox, it is already two ways by default. For other controls, > you'll need to check the documentation. > > To specifiy when the property must be updated (for example on every key > press event, or only when it loses the focus), you need to specify the > UpdateSourceTrigger property. > > You should find examples of that in MSDN. > > For your "Enabled" button, simply bind the IsEnabled property to a boolean > property of your data object. Set this property to true when the data > object has been modified. Set it to false again after the data object has > been saved. > > Greetings, > Laurent > > > -- > Laurent Bugnion [MVP ASP.NET] > Software engineering, Blog: http://www.galasoft-LB.ch > PhotoAlbum: http://www.galasoft-LB.ch/pictures > Support children in Calcutta: http://www.calcutta-espoir.ch |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: Solving an age-old problem Hi, Andrew Whiddett (Home) wrote: > Take a look at : > http://blogs.msdn.com/dancre/archive...-commands.aspx That's a good advice. I keep forgetting about Commands. Thanks, Laurent -- Laurent Bugnion [MVP ASP.NET] Software engineering, Blog: http://www.galasoft.ch PhotoAlbum: http://www.galasoft.ch/pictures Support children in Calcutta: http://www.calcutta-espoir.ch |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Guide to solving BSOD's in Vista | Jason | Vista General | 1 | 04-01-2008 01:01 PM |
| Re: I miss the satisfaction of solving Vista problems... | Ike | Vista General | 1 | 12-15-2007 04:03 PM |
| Re: I miss the satisfaction of solving Vista problems... | Dave T. | Vista General | 1 | 12-07-2007 07:41 PM |
| Solving spell check issues. | Bob | Vista mail | 1 | 02-28-2007 03:07 PM |
| SOLVING PRINTER PROBLEMS | Scot B. | Vista General | 2 | 02-16-2007 11:25 AM |