コード例 #1
0
 private void DeleteAt(int index)
 {
     while (Paths.Items.Count > index)
     {
         Path item = Paths.Items[index] as Path;
         item.PropertyChanged -= P_PropertyChanged;
         foreach (RelativePoint p in item.OwnedPoints)
         {
             Plotter.Children.Remove(p);
         }
         Plotter.Children.Remove(item.OwnedPolyline);
         NonDependencyBinding.CleanupBindingSource(item);
         Paths.Items.RemoveAt(index);
     }
     Paths.SelectedIndex = -1;
     Paths.SelectedItem  = null;
 }
コード例 #2
0
        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;
        }