本文介绍了为什么当我更改其积分集以引用不同的集合时,折线不重绘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还是相当新的Silverlight,所以希望这是一个基本的问题:我有一个折线,其点(类型:点集合)属性绑定到我的视图模型类中的PointsCollection公共成员Pts。当我从ViewModel.Pts添加/删除点时,折线正确地重绘,没有任何问题。但是,如果我将Pts更改为另一个参考,在我的视图模型类中完全不同的PointsCollection对象,则折线不会自动重绘。 Polyline.Points绑定仍然指向ViewModel.Pts,但现在ViewModel.Pts是指ViewModel.OtherPts。当我将ViewModel.Pts重新分配给ViewModel.OtherPts时,我希望折线自动用ViewModel.OtherPts中的数据重绘。



是否有一些事件或某些细微差别依赖属性系统,我缺少?



谢谢!!!



btw-我没有使用任何ObservableProperty或ObservableCollections这里,因为我以为这将在依赖属性+数据绑定系统中工作。

解决方案

你的PointCollection是否是依赖属性在派生自DependencyObject的对象内部,或者是在实现INotifyPropertyChanged接口的对象内部,并且在Points属性设置器中引发PropertyChanged事件?



这些是您从视图模型中通知UI层的更改(您现在引用其他集合)的两个选项。用户界面不会知道更改,除非你这么说。


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.

解决方案

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.

这篇关于为什么当我更改其积分集以引用不同的集合时,折线不重绘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 01:54