我是c#,WPF和MVVM的绝对新手,我尝试创建画布,我可以根据可观察列表的点x和y坐标添加点。我创建了用户控件,这是我的视图模型:
public class ViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public ViewModel()
{
points = new ObservableCollection<Point>();
this.testData();
}
public ObservableCollection<Point> points { get; set; }
private void testData()
{
// points.Add(new Point(0, 50) );
//points.Add(new Point(50, 0));
//points.Add(new Point(13, 73));
//points.Add(new Point(12, 23));
//points.Add(new Point(34, 80));
//points.Add(new Point(322, 225));
//points.Add(new Point(270, 510));
points.Add(new Point(0, 0));
}
}
这就是我在mainWindows.xaml上的内容
<Canvas>
<local:UserControl2 />
</Canvas>
您的澄清非常贴切