![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | 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) |
| | 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) |
| | 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) |
| | 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 | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Problems and Solutions - Need help on problem solving. | General Discussion | |||
| solving startup problems | General Discussion | |||
| Solving a Right Triangle when only the angles are known? | .NET General | |||
| Need help solving this error... | General Discussion | |||
| SOLVING PRINTER PROBLEMS | Vista General | |||