Binding rectangle position to another rectangle
I'm trying to draw a chart and trapped over a design issue. In the Chart-class I defined the shap开发者_如何学Pythone of the area to be drawn in as a Rectangle:
class Chart
{
// ...
public Rectangle drawArea;
public void addAxisDesc(AxisDescription desc)
{
// ... add left Y-axis
// set the axis x-starting position to the start point of the drawing area
desc.shape.X = drawArea.X;
}
}
The Chart-class has the ability to add some axis description, whose shape is also defined by a Rectangle.
My goal is now to keep the values in desc.shape.X and drawArea.X the same. So if drawArea.X changes, desc.shape.X should be modyfied either.
I had a few ideas how to solve this problem, but none of them seemed really good to me:
- Register an event handler and modify the axis' value if the drawArea's value changes
- Set all positions relative to parent element and get the absolute position only at rendering time
Has anybody an idea how to solve this issue or maybe how the problem can be avoided at all?
I suggest you go with the event approach. This is the same approach WPF uses for Data Binding. There even exists an interface for that purpose: INotifyPropertyChanged
精彩评论