I am an absolute newbie to c#, WPF and MVVM and I and trying to create a canvas were I can add points based on an observable colletion's points x and y coordinates. I created the custome user control and this is my view model: I do not understand the binding how to bind the data on my viewmodel to my view. more specifically.
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));
}
}
This is what I have on my view.xaml
<Canvas>
<local:UserControl2 />
</Canvas>
and my user control
public partial class UserControl2 : UserControl
{
public UserControl2()
{
InitializeComponent();
this. DataContext = new ViewModel();
}
}