コード例 #1
0
        void TargetDesignCanvas_PointerPressed(object sender, PointerRoutedEventArgs e)
        {
            if (createControlFunc == null)
            {
                foreach (var v in TargetDesignCanvas.Children)
                {
                    if (v is ArrowCurveSegment)
                    {
                        (v as ArrowCurveSegment).ChangeActive(false);
                    }
                    if (v is DesignControl)
                    {
                        (v as DesignControl).ChangeActive(false);
                    }
                }
                if (DesignManager.SetCurrent != null && Parent != null)
                {
                    var p = Parent as FrameworkElement;
                    DesignManager.SetCurrent(p.DataContext);
                }
                return;
            }
            if (DataContext == null)
            {
                return;
            }
            var dc = DataContext as DesignCanvasViewModel;

            if (dc == null)
            {
                return;
            }
            var control = createControlFunc();

            if (control == null)
            {
                throw new Exception("Can not create control");
            }
            var item = new DesignItem()
            {
                TargetControl = control,
                Left          = e.GetCurrentPoint(TargetDesignCanvas).Position.X,
                Top           = e.GetCurrentPoint(TargetDesignCanvas).Position.Y,
                Width         = double.IsNaN(control.Width) ? 200 : control.Width,
                Height        = double.IsNaN(control.Height) ? 150 : control.Height
            };

            dc.ItemList.Add(item);
            var dcontrol = new DesignControl();

            dcontrol.DataContext = item;
            TargetDesignCanvas.Children.Add(dcontrol);
            //RefreshDataContext(DataContext);
            createControlFunc = null;
            //e.Handled = true;
        }
コード例 #2
0
        DesignConnection getConnectionControl(DesignControl c, RelativePosition type)
        {
            var l = c.GetConnectionList();

            if (type == RelativePosition.Left)
            {
                return(l.FirstOrDefault(v => v.IsLeft));
            }
            if (type == RelativePosition.Right)
            {
                return(l.FirstOrDefault(v => v.IsRight));
            }
            if (type == RelativePosition.Bottom)
            {
                return(l.FirstOrDefault(v => v.IsBottom));
            }
            if (type == RelativePosition.Top)
            {
                return(l.FirstOrDefault(v => v.IsTop));
            }
            return(null);
        }
コード例 #3
0
        void CreateControlInCanvas(FrameworkElement control, double x, double y)
        {
            if (control == null)
            {
                throw new Exception("Can not create control");
            }
            var dc   = DataContext as DesignCanvasViewModel;
            var item = new DesignItem()
            {
                TargetControl = control,
                Left          = x,
                Top           = y,
                Width         = double.IsNaN(control.Width) ? 200 : control.Width,
                Height        = double.IsNaN(control.Height) ? 150 : control.Height
            };

            dc.ItemList.Add(item);
            var dcontrol = new DesignControl();

            dcontrol.DataContext = item;
            TargetDesignCanvas.Children.Add(dcontrol);
        }
コード例 #4
0
        //void ConnectNode()
        public void RefreshView(object value)
        {
            var vm = value as DesignCanvasViewModel;

            if (vm == null)
            {
                return;
            }
            TargetDesignCanvas.Children.Clear();
            vm.ItemList.ToList().ForEach(v =>
            {
                var control = new DesignControl()
                {
                    DataContext = v
                };
                v.OutLinkList.Clear();
                foreach (var outlink in vm.LinkList.Where(u => u.SourceDesignItemID == v.DesignItemID))
                {
                    v.OutLinkList.Add(outlink);
                }
                v.InLinkList.Clear();
                foreach (var inLink in vm.LinkList.Where(u => u.TargetDesignItemID == v.DesignItemID))
                {
                    v.InLinkList.Add(inLink);
                }
                TargetDesignCanvas.Children.Add(control);
            });

            vm.LinkList.ToList().ForEach(v =>
            {
                if (!TargetDesignCanvas.Children.Contains(v.LinkLine))
                {
                    TargetDesignCanvas.Children.Add(v.LinkLine);
                }
                Canvas.SetZIndex(v.LinkLine, 10);
            });
        }