private static void AssignFlowChartViewModeAndView(DesignerItem item, Tuple <ViewModels.ViewModelBase, UserControl> result) { if (result != null) { result.Item2.DataContext = result.Item1; var path = item.Content; item.Content = result.Item2; (result.Item2.FindName("NewContent") as ContentControl).Content = path; item.UpdateLayout(); item.Selected += Item_Selected; } }
private static void AssignSimulationViewModeAndView(DesignerItem item, Tuple <ViewModels.ViewModelBase, UserControl> result) { if (result != null) { result.Item2.DataContext = result.Item1; item.Content = result.Item2; item.UpdateLayout(); item.DataContext = null; var connectors = item.GetConnectors(); foreach (var connector in connectors) { connector.ConnectionChanged += Connector_ConnectionChanged; } } }
static void AddAction(DiagramControl dc, IList newItems) { if (newItems == null || newItems.Count == 0) return; if (newItems.Count > 1) { if (dc.ItemsSource == null) return; if (dc.Check()) { dc.Bind(newItems); } } else //增加单一节点 { foreach (var newItem in newItems) { var model = newItem as DataModel; if (model == null) continue; var item = new DesignerItem(newItem, dc); item.ItemStyle = JsonConvert.DeserializeObject<ItemStyle>(dc.GetItemStyle(newItem)); item.ItemStyle.designerItem = item; var parentid = dc.GetPId(newItem); if (parentid.IsNotEmpty()) { var parent = dc.Manager.GetDesignerItemById(parentid); parent.ChildrenDesignerItems.Add(item); item.ParentDesignerItem = parent; dc.Manager.DrawChild(parent, item, new List<DesignerItem>()); if (dc.IsAddAfter)/*增加子节点*/ { var childs = dc.Manager.GetAllSubItems(parent).Where(x => !x.Equals(item)); var lastChild = !childs.Any() ? parent : childs.Aggregate((a, b) => Canvas.GetTop(a) > Canvas.GetTop(b) ? a : b); var below = dc.DesignerItems.Where(x => Canvas.GetTop(x) > Canvas.GetTop(lastChild)).ToList(); dc.AddToMessage("增加子节点", dc.Manager.GetTime(() => { below.ForEach(x => { Canvas.SetTop(x, Canvas.GetTop(x) + item.ActualHeight); }); Canvas.SetTop(item, Canvas.GetTop(lastChild) + lastChild.ActualHeight); })); dc.Manager.SetSelectItem(item); } else/*增加相邻节点*/ { var s = dc.DesignerCanvas.SelectionService.CurrentSelection.ConvertAll<DesignerItem>(x => x as DesignerItem); if (!s.Any()) return; var selectedItem = s.FirstOrDefault(); if (selectedItem == null) return; DesignerItem libling; var down = dc.DesignerItems.Where(x => x.Level == selectedItem.Level && Canvas.GetTop(x) > Canvas.GetTop(selectedItem) && x.ParentDesignerItem.Equals(selectedItem.ParentDesignerItem)).ToList(); if (down.Any()) { libling = down.Aggregate((a, b) => Canvas.GetTop(a) < Canvas.GetTop(b) ? a : b); var below = dc.DesignerItems.Where(x => Canvas.GetTop(x) > Canvas.GetTop(libling)).ToList(); below.Add(libling); dc.AddToMessage("增加相邻节点", dc.Manager.GetTime(() => { below.ForEach(x => { Canvas.SetTop(x, Canvas.GetTop(x) + item.ActualHeight); }); Canvas.SetTop(item, Canvas.GetTop(libling) - libling.ActualHeight); })); } else { var childs = dc.Manager.GetAllSubItems(parent); var lastChild = !childs.Any() ? parent : childs.Aggregate((a, b) => Canvas.GetTop(a) > Canvas.GetTop(b) ? a : b); var below = dc.DesignerItems.Where(x => Canvas.GetTop(x) > Canvas.GetTop(lastChild)).ToList(); dc.AddToMessage("增加相邻节点", dc.Manager.GetTime(() => { below.ForEach(x => { Canvas.SetTop(x, Canvas.GetTop(x) + item.ActualHeight); }); Canvas.SetTop(item, Canvas.GetTop(lastChild) + lastChild.ActualHeight); })); } } } else { dc.Manager.DrawRoot(item); item.ApplyTemplate(); item.SetTemplate(); item.UpdateLayout(); if (dc.ItemsSource.Count > 1) { Canvas.SetTop(item, dc.GetTop(newItem) - item.ActualHeight / 2); Canvas.SetLeft(item, dc.GetLeft(newItem) - item.ActualWidth / 2); } else { Canvas.SetTop(item, 0); Canvas.SetLeft(item, 0); } } dc.DesignerItems.Add(item); dc.Manager.SetSelectItem(item); dc.Manager.Scroll(item); dc.Manager.SavePosition(); } } }
public List<DesignerItem> DrawDesignerItems(DesignerItem designerItem) { var list = new List<DesignerItem>(); if (designerItem == null) return list; designerItem.UpdateLayout(); designerItem.SetTemplate(); var childs = designerItem.ChildrenDesignerItems.OrderBy(x => x.Top); foreach (var childItem in childs) { DrawChild(designerItem, childItem, list); list.AddRange(DrawDesignerItems(childItem)); } return list; }
public void DrawChild(DesignerItem designerItem, DesignerItem childItem, List<DesignerItem> list) { if (designerItem == null) return; DrawDesignerItem(childItem);/*创建子节点*/ childItem.UpdateLayout(); childItem.SetTemplate(); var top = Canvas.GetTop(designerItem) + designerItem.ActualHeight + list.Sum(x => x.ActualHeight); list.Add(childItem); var left = Canvas.GetLeft(designerItem) + GetOffset(designerItem); Canvas.SetTop(childItem, top); Canvas.SetLeft(childItem, left); SavePosition(childItem); childItem.UpdateLayout(); var source = GetItemConnector(designerItem, PARENT_CONNECTOR); var sink = GetItemConnector(childItem, "Left"); if (source == null || sink == null) return; #region 创建连线 var conn = new Connection(source, sink); /*创建连线*/ DesignerCanvas.Children.Add(conn); /*放到画布上*/ Panel.SetZIndex(conn, -10000); #endregion childItem.CanCollapsed = true; childItem.UpdateExpander(); }
void T_LostFocus(object sender, DesignerItem item, double oldHeight) { var textBox = sender as TextBox; DesignerCanvas.Children.Remove(textBox); //Arrange(); var list = _diagramControl.DesignerItems.Where(x => Canvas.GetTop(x) > Canvas.GetTop(item)).ToList(); item.UpdateLayout(); var height = item.ActualHeight; var h = height - oldHeight; list.ForEach(x => Canvas.SetTop(x, Canvas.GetTop(x) + h)); _diagramControl.IsOnEditing = false; GlobalInputBindingManager.Default.Recover(); _diagramControl.Focus(); }