问题描述
我想在视图中为画布上的不同对象绘制图形。我可以使用PointCollection存储不同对象的点。并创建一个PointCollection类型的属性。然后在xaml中我将该行绑定到此PointCollection属性。
我尝试过:
我只需要知道它是否可能。
I want to plot graph for different objects on canvas in the view. Can I use PointCollection for storing the points for different objects. And make a property of type PointCollection. Then in xaml I will bind the line to this PointCollection property.
What I have tried:
I just need to know is it possible or not.
推荐答案
[System.ComponentModel.TypeConverter(typeof(System.Windows.Media.PointCollectionConverter))]
public sealed class PointCollection : System.Windows.Freezable, IFormattable, System.Collections.Generic.ICollection<System.Windows.Point>, System.Collections.Generic.IEnumerable<System.Windows.Point>, System.Collections.Generic.IList<System.Windows.Point>, System.Collections.IList
您需要做的是为 PointCollection
类编写一个Proxy类包装器,该类实现 System.Collections.Specialized.INotifyCollectionChanged
和 System.ComponentModel.INotifyPropertyChanged
数据绑定接口正常工作。
要查看前其中,请看一下数据绑定集合 []。
What you need to do is write a Proxy class wrapper for the PointCollection
class that implements both the System.Collections.Specialized.INotifyCollectionChanged
and System.ComponentModel.INotifyPropertyChanged
interfaces for Data Binding to work properly.
To see an example of this, take a look at the data binding collection ObservableCollection<T> Class (System.Collections.ObjectModel)[^].
这篇关于我们可以在WPF应用程序中的viewmodel中使用pointcollection吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!