简体   繁体   中英

WPF - How to implement INotifyPropertyChanged when Properties are dynamic

I have a business object that implements a collection of PropertyObjects.

BusinessObject SomeCollection Property1Object (Name=Height) Property2Object (Name=Width)

Currently, I am setting the DataContext of UserControl to be the BusinessObject. I've found that I CAN reference into the collection in the binding with something like this, say in a textBox..

UserControl.DataContext = BusinessObject UserControl.TextBlock Text="{Binding Collection[Height].Value}"

Now, at what level can I properly implement INotifyPropertyChanged, even though at the higher level it isn't a property at all.

It's easy enough to see and raise the at the lowest level, the PropertyObject, but is that enough for the binding to work?

Thanks, jeff

If I'm understanding you correctly, every object in the Collection array has a property called Value , which is what is displayed in the TextBlock in your UserControl . As long as each object in the array implements INotifyPropertyChanged , and fires the event when the value of Value changes, the text in the TextBlock should update (you might need to change the BindingMode to TwoWay as well, I'm not sure though).

如果您伪造自己的集合,则需要实现INotifyCollectionChanged( http://msdn.microsoft.com/zh-cn/library/system.collections.specialized.inotifycollectionchanged.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM