data binding - Bind a property to another property in C# -
i have class named grid, composed of 2 other classes circle , line.
public class grid { public circle circle {get; set;} public line line {get; set;} } i want geometry of line stay connected geometry of circle. means when drag or move circle. want line notified somehow , updated geometry according new location of circle.
of course can create new grid updated geometries of circle , line, not want create new grid. want somehow bind end-points of line example circle's center.
what technologies in c# allows me this? delegates? inotifypropertychanged?
public class circle : inotifypropertychanged { private int radius; public int radius { { return radius; } set { radius = value; raisepropertychanged("radius"); } } public event propertychangedeventhandler propertychanged; private void raisepropertychanged(string propertyname) { var propchange = propertychanged; if (propchange == null) return; propchange(this, new propertychangedeventargs(propertyname)); } } then in grid.cs
public class grid { private circle circle; public circle circle { { return circle; } set { circle = value; if (circle != null) circle.propertychanged += onpropertychanged; } } private void onpropertychanged(object sender, propertychangedeventargs e) { if (e.propertyname == "radius") // line } }
Comments
Post a Comment