Wpf datagrid binding not updating
So if you want to know the change in items of the collection you need to subscribe to the Collection Changed event of the Observable Collection But there is a problem with Observable Collection.
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!
So although I was firing an event that looked like INotify Property Changed.
Property Changed, I was actually just firing my own event with the same name 🙂 So there you have it, I’m an idiot 🙂 The moral of the story is, when your bindings aren’t working check the obvious: Hello there!
Beatriz Costa posted a generic solution, but I found it a bit tedious to explicitly update every single control on my dialog.
As a result, I came up with a solution that recursively processes a visual tree from a given starting point and updates all controls that provide one or several bindings of your choice: Using the above method is quite simple: Just set a starting point (window, grid, whatever) along with an arbitrary number of dependency properties you’d like to have processed.
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!
What I wasn't doing with that was telling the Datagrid to look at the underlying datasource and refresh the UI from that. Yeah, I did feel a bit silly after finding that out.