Example #1
0
        void DragThumb_DragDelta(object sender, DragDeltaEventArgs e)
        {
            DesignerItem   designerItem = this.DataContext as DesignerItem;
            DesignerCanvas designer     = VisualTreeHelper.GetParent(designerItem) as DesignerCanvas;

            if (designerItem != null && designer != null && designerItem.IsSelected)
            {
                double minLeft = double.MaxValue;
                double minTop  = double.MaxValue;

                // we only move DesignerItems
                var designerItems = from item in designer.SelectedItems
                                    where item is DesignerItem
                                    select item;

                foreach (DesignerItem item in designerItems)
                {
                    double left = Canvas.GetLeft(item);
                    double top  = Canvas.GetTop(item);

                    minLeft = double.IsNaN(left) ? 0 : Math.Min(left, minLeft);
                    minTop  = double.IsNaN(top) ? 0 : Math.Min(top, minTop);
                }

                double deltaHorizontal = Math.Max(-minLeft, e.HorizontalChange);
                double deltaVertical   = Math.Max(-minTop, e.VerticalChange);

                foreach (DesignerItem item in designerItems)
                {
                    double left = Canvas.GetLeft(item);
                    double top  = Canvas.GetTop(item);

                    if (double.IsNaN(left))
                    {
                        left = 0;
                    }
                    if (double.IsNaN(top))
                    {
                        top = 0;
                    }

                    Canvas.SetLeft(item, left + deltaHorizontal);
                    Canvas.SetTop(item, top + deltaVertical);
                }

                designer.InvalidateMeasure();
                e.Handled = true;
            }
        }
Example #2
0
        protected override void OnDrop(DragEventArgs e)
        {
            base.OnDrop(e);
            DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject;

            if (dragObject != null && !String.IsNullOrEmpty(dragObject.Xaml))
            {
                DesignerItem newItem = null;
                Object       content = XamlReader.Load(XmlReader.Create(new StringReader(dragObject.Xaml)));

                if (content != null)
                {
                    newItem         = new DesignerItem("");
                    newItem.Content = content;

                    Point position = e.GetPosition(this);

                    if (dragObject.DesiredSize.HasValue)
                    {
                        Size desiredSize = dragObject.DesiredSize.Value;
                        newItem.Width  = desiredSize.Width;
                        newItem.Height = desiredSize.Height;

                        DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2));
                        DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2));
                    }
                    else
                    {
                        DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X));
                        DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y));
                    }

                    this.Children.Add(newItem);

                    //update selection
                    foreach (ISelectable item in this.SelectedItems)
                    {
                        item.IsSelected = false;
                    }
                    SelectedItems.Clear();
                    newItem.IsSelected = true;
                    this.SelectedItems.Add(newItem);
                }

                e.Handled = true;
            }
        }
Example #3
0
        private Connector GetConnector(string itemID, String connectorName)
        {
            DesignerItem designerItem = (from item in this.Children.OfType <DesignerItem>()
                                         where item.CurrentSerialNumber == itemID
                                         select item).FirstOrDefault();

            if (designerItem != null)
            {
                designerItem.ApplyTemplate();
            }
            Control connectorDecorator = designerItem.Template.FindName("PART_ConnectorDecorator", designerItem) as Control;

            if (connectorDecorator != null)
            {
                connectorDecorator.ApplyTemplate();
            }
            return(connectorDecorator.Template.FindName(connectorName, connectorDecorator) as Connector);
        }
Example #4
0
 void DesignerItem_Loaded(object sender, RoutedEventArgs e)
 {
     if (base.Template != null)
     {
         ContentPresenter contentPresenter =
             this.Template.FindName("PART_ContentPresenter", this) as ContentPresenter;
         if (contentPresenter != null)
         {
             if (VisualTreeHelper.GetChildrenCount(contentPresenter) > 0)
             {
                 UIElement contentVisual = VisualTreeHelper.GetChild(contentPresenter, 0) as UIElement;
                 if (contentVisual != null)
                 {
                     DragThumb thumb = this.Template.FindName("PART_DragThumb", this) as DragThumb;
                     Control   connectorDecorator = this.Template.FindName("PART_ConnectorDecorator", this) as Control;
                     if (thumb != null)
                     {
                         ControlTemplate template =
                             DesignerItem.GetDragThumbTemplate(contentVisual) as ControlTemplate;
                         if (template != null)
                         {
                             thumb.Template = template;
                         }
                     }
                     if (connectorDecorator != null)
                     {
                         ControlTemplate template =
                             DesignerItem.GetConnectorDecoratorTemplate(contentVisual) as ControlTemplate;
                         if (template != null)
                         {
                             connectorDecorator.Template = template;
                         }
                     }
                 }
             }
         }
     }
 }
Example #5
0
        /// <summary>
        /// 初始化流程图
        /// </summary>
        /// <param name="flowList"></param>
        public void LoadFlowChart(List <Tx_Node> flowList)
        {
            _countedNodes = new List <Tx_Node>();
            _nodes        = new List <Tx_Node>();
            _allEntrys    = new List <Tx_Entry>();
            if (flowList == null || flowList.Count() < 1)
            {
                return;
            }
            //int m_MaxFlowCode = flowList.Count() + 1;
            startNode = (Convert.ToInt32(flowList.Select(x => x.Code).Min()) - 1).ToString();
            endNode   = (Convert.ToInt32(flowList.Select(x => x.Code).Max()) + 1).ToString();
            _nodes.Add(new Tx_Node(startNode, "", "开始"));
            _nodes.Add(new Tx_Node(endNode, "", "结束"));
            LayOut(flowList);//确定布局,初始化数据
            if (_countedNodes == null)
            {
                return;
            }
            #region 构造流程节点
            foreach (var node in _countedNodes)
            {
                Label lbl = new Label {
                    Width = 150, Height = 45, Content = node.Name, Tag = node.Code
                };
                lbl.Style = nodeStyle as Style;
                DesignerItem item = new DesignerItem(node.Code);
                item.Remark    = node.Content; //备注
                item.ErrorInfo = node.ErrInfo; //错误信息
                switch (node.Stat.ToUpper())
                {
                case "Z":
                    item.SourceTipSymbol = DesignerItemTip.Error;     //失败
                    item.ToolTip         = "结账失败";
                    break;

                case "Y":
                    item.SourceTipSymbol = DesignerItemTip.Success;    //成功
                    item.ToolTip         = "结账成功";
                    break;

                case "N":
                    item.SourceTipSymbol = DesignerItemTip.UnHandled;  //未处理
                    item.ToolTip         = "未处理";
                    break;

                case "S":
                    item.SourceTipSymbol = DesignerItemTip.Execute;    //正在执行
                    //if (_focusAdornerLayer == null)
                    //            {
                    //               _focusAdornerLayer = AdornerLayer.GetAdornerLayer(item);
                    //           }
                    //           _preAdorder = new FocusAdorner(item);
                    //           _preAdorder.IsClipEnabled = true;
                    //           _focusAdornerLayer.Add(_preAdorder);
                    item.ToolTip = "正在执行";
                    break;

                default:
                    item.SourceTipSymbol = DesignerItemTip.None;
                    break;
                }
                Canvas.SetLeft(item, Double.Parse("10", CultureInfo.InvariantCulture) + node.X);
                Canvas.SetTop(item, Double.Parse("5", CultureInfo.InvariantCulture) + node.Y);
                Canvas.SetZIndex(item, Int32.Parse("0"));
                item.Content = lbl;
                item.ToolTip = node.Content;
                if (!string.IsNullOrEmpty(node.Sub_Code.Trim()))
                {
                    item.IsDragConnectionOver = true;
                }
                this.Children.Add(item);
                ControlTemplate template = DesignerItem.GetConnectorDecoratorTemplate(item) as ControlTemplate;
                DesignerItem.SetConnectorDecoratorTemplate(item, template);
            }
            #endregion

            #region  构造流程线条
            this.InvalidateVisual();//使元素的呈现无效,并强制执行完整的新布局处理过程。布局循环完成后
            if (_allEntrys == null)
            {
                return;
            }
            foreach (Tx_Entry entry in _allEntrys)
            {
                string sourceID            = entry.StartNode;
                string sinkID              = entry.EndNode;
                string sourceConnectorName = "ConnectorBottomName";
                string sinkConnectorName   = "ConnectorTopName";
                if (!string.IsNullOrEmpty(sinkID) && !string.IsNullOrEmpty(sourceID))
                {
                    String     strContent      = entry.Condition;
                    Connector  sourceConnector = GetConnector(sourceID, sourceConnectorName);
                    Connector  sinkConnector   = GetConnector(sinkID, sinkConnectorName);
                    Connection connection      = new Connection(sourceConnector, sinkConnector, strContent);
                    Canvas.SetZIndex(connection, 5);
                    this.Children.Add(connection);
                }
            }
            #endregion
        }
Example #6
0
        void ResizeThumb_DragDelta(object sender, DragDeltaEventArgs e)
        {
            DesignerItem   designerItem = this.DataContext as DesignerItem;
            DesignerCanvas designer     = VisualTreeHelper.GetParent(designerItem) as DesignerCanvas;

            if (designerItem != null && designer != null && designerItem.IsSelected)
            {
                double minLeft, minTop, minDeltaHorizontal, minDeltaVertical;
                double dragDeltaVertical, dragDeltaHorizontal;

                // only resize DesignerItems
                var selectedDesignerItems = from item in designer.SelectedItems
                                            where item is DesignerItem
                                            select item;

                CalculateDragLimits(selectedDesignerItems, out minLeft, out minTop,
                                    out minDeltaHorizontal, out minDeltaVertical);

                foreach (DesignerItem item in selectedDesignerItems)
                {
                    if (item != null)
                    {
                        switch (base.VerticalAlignment)
                        {
                        case VerticalAlignment.Bottom:
                            dragDeltaVertical = Math.Min(-e.VerticalChange, minDeltaVertical);
                            item.Height       = item.ActualHeight - dragDeltaVertical;
                            break;

                        case VerticalAlignment.Top:
                            double top = Canvas.GetTop(item);
                            dragDeltaVertical = Math.Min(Math.Max(-minTop, e.VerticalChange), minDeltaVertical);
                            Canvas.SetTop(item, top + dragDeltaVertical);
                            item.Height = item.ActualHeight - dragDeltaVertical;
                            break;

                        default:
                            break;
                        }

                        switch (base.HorizontalAlignment)
                        {
                        case HorizontalAlignment.Left:
                            double left = Canvas.GetLeft(item);
                            dragDeltaHorizontal = Math.Min(Math.Max(-minLeft, e.HorizontalChange), minDeltaHorizontal);
                            Canvas.SetLeft(item, left + dragDeltaHorizontal);
                            item.Width = item.ActualWidth - dragDeltaHorizontal;
                            break;

                        case HorizontalAlignment.Right:
                            dragDeltaHorizontal = Math.Min(-e.HorizontalChange, minDeltaHorizontal);
                            item.Width          = item.ActualWidth - dragDeltaHorizontal;
                            break;

                        default:
                            break;
                        }
                    }
                }
                e.Handled = true;
            }
        }