更新时间:2023-02-10 19:33:24
更改您的PointCollections属性为依赖属性:
Change your PointCollections Property to a dependency property:
public PointCollection Pts
{
get { return (PointCollection)GetValue(PtsProperty); }
set { SetValue(PtsProperty, value); }
}
// Using a DependencyProperty as the backing store for Pts. This enables animation, styling, binding, etc...
public static readonly DependencyProperty PtsProperty =
DependencyProperty.Register("Pts", typeof(PointCollection), typeof(ViewModel), new UIPropertyMetadata(new PointCollection()));
BTW执行此操作,您不需要触发PropertyChanged事件。
BTW Doing this, you won't need to fire the PropertyChanged event.
哦,对不起,你的对象需要继承自DependencyObject
Oh sorry, and your object needs to inherit from DependencyObject
public class ViewModel : DependencyObject
{
//...
}