private void pointBindToCanvas(RelativePoint p, Canvas c) { Binding canvasWidth = new Binding("ActualWidth"); canvasWidth.Source = c; p.SetBinding(RelativePoint.CanvasWidthProperty, canvasWidth); Binding canvasHeight = new Binding("ActualHeight"); canvasHeight.Source = c; p.SetBinding(RelativePoint.CanvasHeightProperty, canvasHeight); }
private void Paths_ItemAdded(object item) { Path p = item as Path; Paths.SelectedItem = p; if (Paths.Items.Count == 1) { //this is the only path p.SetStartPoint(originX.Value ?? 0, originY.Value ?? 0); //Todo: make this a binding as well Binding firstX = new Binding("StartX"); firstX.Mode = BindingMode.TwoWay; firstX.Source = p; BindingOperations.SetBinding(originX, DoubleUpDown.ValueProperty, firstX); Binding firstY = new Binding("StartY"); firstY.Mode = BindingMode.TwoWay; firstY.Source = p; BindingOperations.SetBinding(originY, DoubleUpDown.ValueProperty, firstY); } else { Path prev = Paths.Items[Paths.Items.Count - 2] as Path; p.SetStartPoint(prev.EndX, prev.EndY); NonDependencyBinding.Create(prev, "EndX", p, "StartX"); NonDependencyBinding.Create(prev, "EndY", p, "StartY"); } RelativePoint start = makeGuidePoint(); RelativePoint end = makeGuidePoint(); Binding startX = new Binding("StartX"); startX.Source = p; start.SetBinding(RelativePoint.XPositionProperty, startX); Binding startY = new Binding("StartY"); startY.Source = p; start.SetBinding(RelativePoint.YPositionProperty, startY); Binding endX = new Binding("EndX"); endX.Source = p; end.SetBinding(RelativePoint.XPositionProperty, endX); Binding endY = new Binding("EndY"); endY.Source = p; end.SetBinding(RelativePoint.YPositionProperty, endY); Plotter.Children.Add(start); Plotter.Children.Add(end); p.OwnedPoints.Add(start); p.OwnedPoints.Add(end); if (p is QuadraticPath) { RelativePoint mid = makeGuidePoint(); Binding gx = new Binding("GuidePointX"); gx.Source = p; mid.SetBinding(RelativePoint.XPositionProperty, gx); Binding gy = new Binding("GuidePointY"); gy.Source = p; mid.SetBinding(RelativePoint.YPositionProperty, gy); Plotter.Children.Add(mid); p.OwnedPoints.Add(mid); } RenderPath(p); //everything is now set. attach an event handler to re-render paths p.PropertyChanged += P_PropertyChanged; }