Normally my View Models inherit from my View Model Base base class, which provides a Raise Property Changed method and, when in debug mode, uses reflection to check if the property name is valid.Now I’d recently refactored the code so this particular View Model wasn’t using the base class, so my first instinct was that I’d simply mistyped the property name magic string in the event – but that was all fine.
I threw in a few breakpoints and I could see my View Model was changing, I could see the On Property Changed method being hit, but there didn’t seem to be any listeners and as a result my UI was just ignoring the changes.
After a few minutes of head scratching I noticed that although my class was firing the Property Changed event correctly, I hadn’t added INotify Property Changed to my class declaration when I removed the base class!
The value will be inherited by the key Text Boxes and Text Block.
Modify the constructor for the window, as follows: You can now run the program to see the results.
We saw this with a Slider and a Text Block that were bound to the same value.
As the Slider was manipulated, the Text Block showed the changing value.
You can use this automatic behaviour to tell the user interface to update. Create a new WPF application project in Visual Studio named, "INotify Property Changed Demo".
When an action happens that causes a property to change that would not normally cause an update in the WPF controls bound to it, you raise the event and name the modified property. Once ready replace the XAML of the main window with the code below: property that combines the first and last names into a single string.
My name is Steven Robbins, and this is my allegedly technical blog.
These days I generally work in C# and SQL, but in the past I’ve developed in everything from Assembly Language (68000 and x86) through to VB. I’ve also done my time in the support/engineering side of IT, so I’m pretty much a geek through and through 🙂 I’m a firm believer that reading and “best practices” are no substitute for using your brain!
I've made a program which stores any number of objects of my type Project.