c# - add circle(points) to canvas from a ObservableCollection to view using mvvm -


this question has answer here:

i absolute newbie c#, wpf , mvvm , , trying create canvas can add points based on observable colletion's points x , y coordinates. created custome user control , view model: not understand binding how bind data on viewmodel 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 have on view.xaml

<canvas>  <local:usercontrol2 /> </canvas> 

and user control

  public partial class usercontrol2 : usercontrol   {      public usercontrol2()      {          initializecomponent();         this. datacontext = new viewmodel();      }   } 

you try 2 things: raise notifyproprtychanged event in set section of observable collection ( know, silly, had luck sollution in similar case) or (also worked me) create new, local observablecollection in testdata function, fill values , set observable collection local filled observable collection. try both of ways in combination. please recheck property binding in view. sure set notifyoncodeupdated (or something) , notifyontargetupdated (have no visual studio check here)


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -