![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| 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 | |||