why doesn't a polyline redraw when I change its Points collection to reference a different collection?

自作多情 提交于 2019-12-25 03:16:32

问题


I'm still fairly new to silverlight, so hopefully this is an elementary question: I have a polyline whose 'Points' (type: PointsCollection) property is bound to a PointsCollection public member, Pts, in my view model class. When I add/remove points from ViewModel.Pts, the polyline redraws correctly without any problem. However, if I change Pts to be a reference to another, totally different PointsCollection object in my view model class, then the polyline doesn't automatically redraw. The Polyline.Points binding still refers to ViewModel.Pts, but now ViewModel.Pts refers to ViewModel.OtherPts. When I reassign ViewModel.Pts to ViewModel.OtherPts, I want the polyline to automatically redraw with the data in ViewModel.OtherPts.

Is there some event or some nuance in the dependency property system that I'm missing?

Thanks!!!

btw- I'm not using any ObservableProperty or ObservableCollections here since I thought this would all work within the dependency property + databinding system.


回答1:


Is your PointCollection a DependencyProperty inside an object that derived from DependencyObject, or, alternatively, is it inside an object that implements the INotifyPropertyChanged interface, and do you raise the PropertyChanged event in the Points property setter?

Those are the two options you have to notify the UI layer of the change (that you now reference a different collection) from the view model. The UI won't know about the change unless you tell it so.



来源:https://stackoverflow.com/questions/3132756/why-doesnt-a-polyline-redraw-when-i-change-its-points-collection-to-reference-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!