Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

Solving an age-old problem

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 05-29-2007   #1 (permalink)
Michael Jackson
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 SpecsSystem Spec
Old 05-30-2007   #2 (permalink)
Laurent Bugnion, MVP
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 SpecsSystem Spec
Old 06-08-2007   #3 (permalink)
Andrew Whiddett \(Home\)
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 SpecsSystem Spec
Old 06-08-2007   #4 (permalink)
Laurent Bugnion, MVP
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 SpecsSystem Spec
Closed Thread
Update your Vista Drivers Update Your Drivers Now!!

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


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51