Currently I am leading a project to rewrite one of my organization’s major internal apps. I got to choose the architecture and decided on WPF/XAML, the MVVM pattern, and Entity Framework 6. All three are new to me and have pretty significant learning curves. Welcome to the new world. Well, new world for me anyway and apparently old world for everyone else since 2009.
Pretty early on I fell into what I now know is a common WPF “trap for new players”. When you display a list box or gridview of items in an ObservableCollection, changes to items within the ObservableCollection don’t fire its INotifyPropertyChanged event. Fortunately this problem is well known and solutions are easy to find. I ended up using this one-http://www.codeproject.com/Articles/660423/ObservableCollection-notification-on-member-change
Unfortunately this only solved half of the problem for me. I’m using Entity Framework in Database First Mode because I have to use an existing SQL Server database. Therefore my ObservableCollections don’t implement INotifyPropertyChanged, even though, after implementing the above solution, the ObservableCollection is listening for it.
After lots of Googling and testing I ended up using PropertyChanged.Fody to fix this. It implements INotifyPropertyChanged at compile time into whatever model objects you specify- http://www.codeproject.com/Tips/853383/Adding-INotifyPropertyChanged-to-Entity-Framework
I hope someone will find this helpful.
No comments:
Post a Comment