Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - INotifyPropertyChanged Question

 
 
Old 05-23-2006   #1 (permalink)
Fidget Brain


 
 

INotifyPropertyChanged Question

lets say I have a class called Wage which implements the
INotifyPropertyChanged interface. the Wage class contains 2 properties, a
read/write property for the wage, and a read-only property for the Tax. Like
this:

public class Wage
{
...
public double NetAmount
{
get
{
return netAmount;
// ???
OnPropertyChanged("NetAmount");
OnPropertyChanged("Tax");
}
set{...}
}

public double Tax
{
get
{
return netAmount * taxRate;
}
}
...
}

As far as I can see, this means that whenever the NetAmount property
changes, I must also ensure that I raise a PropertyChangedEvent for the Tax
property as well, as this property is derived partly from the net amount.
this architecture seems a bit flimsy and could easily lead to properties not
getting updated properly.

1. Am I doing something wrong in the above architecture?

2. Is there a way to call the PropertyChanged event on all Properties of a
class simultaneously, ensuring that all bound controls get rebound?

Thanks.




My System SpecsSystem Spec
Old 05-23-2006   #2 (permalink)
Douglas Stockwell


 
 

Re: INotifyPropertyChanged Question

1. Assuming that your example was actually a typo and you really meant to
fire the events from the setter.

Looks fine to me, I often do this and haven't run into any problems.

If you really feel it's too fragile and you can spare the bytes, then you
could always cache the calculated Tax value through a setter on the Tax property
and fire the event from there.

2. Not that I'm aware of. Of course, depending on your architecture you may
be able to fire a propertychanged from a containing parent to the same effect.

eg. fire a PropertyChanged("Wage") on Data.

public class Data
{
public Wage Wage
{
get { ... };
}
}

- Doug

> lets say I have a class called Wage which implements the
> INotifyPropertyChanged interface. the Wage class contains 2
> properties, a read/write property for the wage, and a read-only
> property for the Tax. Like this:
>
> public class Wage
> {
> ...
> public double NetAmount
> {
> get
> {
> return netAmount;
> // ???
> OnPropertyChanged("NetAmount");
> OnPropertyChanged("Tax");
> }
> set{...}
> }
> public double Tax
> {
> get
> {
> return netAmount * taxRate;
> }
> }
> ...
> }
> As far as I can see, this means that whenever the NetAmount property
> changes, I must also ensure that I raise a PropertyChangedEvent for
> the Tax property as well, as this property is derived partly from the
> net amount. this architecture seems a bit flimsy and could easily lead
> to properties not getting updated properly.
>
> 1. Am I doing something wrong in the above architecture?
>
> 2. Is there a way to call the PropertyChanged event on all Properties
> of a class simultaneously, ensuring that all bound controls get
> rebound?
>
> Thanks.
>



My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
IE8 Question Vista General
escape character question - hopefully an easy question PowerShell
vista genral question and ultimate question Vista General
Dual boot system question and family deal discount question Vista General
RC1 Cd Key Question Vista installation & setup


Vista Forums 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 Ltd

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