private void _AttachDockView(UIElement view, LayoutGroup target) { if (view is LayoutGroupPanel) { foreach (UIElement item in (view as LayoutGroupPanel).Children) { _AttachDockView(item, target); } } if (view is BaseGroupControl) { var model = (view as BaseGroupControl).Model as LayoutGroup; var _children = new List <IDockElement>(model.Children.Reverse()); model.Dispose(); foreach (var item in _children) { target.Attach(item, _index); } } if (view is IDisposable) { (view as IDisposable).Dispose(); } }
/// <summary> /// 以Float模式向DockManager注册一个DockElement /// </summary> /// <param name="title">标题栏文字</param> /// <param name="content">内容</param> /// <param name="imageSource">标题栏图标</param> /// <param name="side">停靠方向(默认左侧)</param> /// <param name="desiredWidth">期望的宽度</param> /// <param name="desiredHeight">期望的高度</param> /// <returns></returns> public void RegisterFloat(IDockSource content, DockSide side = DockSide.Left, double desiredWidth = Constants.DockDefaultWidthLength, double desiredHeight = Constants.DockDefaultHeightLength) { DockElement ele = new DockElement() { ID = id++, Title = content.Header, Content = content as UIElement, ImageSource = content.Icon, Side = side, Mode = DockMode.Float, DesiredWidth = desiredWidth, DesiredHeight = desiredHeight }; var ctrl = new DockControl(ele); var group = new LayoutGroup(side, ele.Mode, this); group.Attach(ele); AddDockControl(ctrl); content.DockControl = ctrl; }
/// <summary> /// 以Float模式向DockManager注册一个DockElement /// </summary> /// <param name="title">标题栏文字</param> /// <param name="content">内容</param> /// <param name="imageSource">标题栏图标</param> /// <param name="side">停靠方向(默认左侧)</param> /// <param name="desiredWidth">期望的宽度</param> /// <param name="desiredHeight">期望的高度</param> /// <returns></returns> public void RegisterFloat(IDockSource content, DockSide side = DockSide.Left, int?id = null, double desiredWidth = Constants.DockDefaultWidthLength, double desiredHeight = Constants.DockDefaultHeightLength, double floatLeft = 0.0, double floatTop = 0.0) { DockElement ele = new DockElement() { ID = id.HasValue ? id.Value : _GetID(), Title = content.Header, Content = content, ImageSource = content.Icon, Side = side, Mode = DockMode.Float, DesiredWidth = desiredWidth, DesiredHeight = desiredHeight, FloatLeft = floatLeft, FloatTop = floatTop }; var ctrl = new DockControl(ele); var group = new LayoutGroup(side, ele.Mode, this); group.Attach(ele); AddDockControl(ctrl); content.DockControl = ctrl; }
private void _InitDragItem() { LayoutGroup group; IDockElement ele; var mouseP = DockHelper.GetMousePosition(DockManager); switch (_dragItem.DockMode) { case DockMode.Normal: if (_dragItem.RelativeObj is ILayoutGroup) { var _layoutGroup = _dragItem.RelativeObj as LayoutGroup; #region AttachObj var _parent = _layoutGroup.View.DockViewParent as LayoutGroupPanel; var _mode = _parent.Direction == Direction.Horizontal ? AttachMode.Left : AttachMode.Top; if (_parent.Direction == Direction.None) { _mode = AttachMode.None; } var _index = _parent.IndexOf(_layoutGroup.View); if (_parent.Children.Count - 1 > _index) { _layoutGroup.AttachObj = new AttachObject(_layoutGroup, _parent.Children[_index + 2] as INotifyDisposable, _index, _mode); } else { _layoutGroup.AttachObj = new AttachObject(_layoutGroup, _parent.Children[_index - 2] as INotifyDisposable, _index, _mode); } #endregion //这里移动的一定是AnchorSideGroup,故将其从父级LayoutGroupPanel移走,但不Dispose留着构造浮动窗口 if ((_layoutGroup.View as ILayoutGroupControl).TryDeatchFromParent(false)) { //注意重新设置Mode (_layoutGroup as BaseLayoutGroup).Mode = DockMode.Float; _dragWnd = new AnchorGroupWindow(DockManager) { Left = mouseP.X - _dragItem.ClickPos.X - 1, Top = mouseP.Y - _dragItem.ClickPos.Y - 1 }; _dragWnd.AttachChild(_layoutGroup.View, AttachMode.None, 0); _dragWnd.Show(); } } else if (_dragItem.RelativeObj is IDockElement) { ele = _dragItem.RelativeObj as IDockElement; #region AttachObj var _parent = (ele.Container as LayoutGroup).View as BaseGroupControl; var _index = ele.Container.IndexOf(ele); #endregion if (ele.IsDocument) { group = new LayoutDocumentGroup(DockMode.Float, DockManager); } else { group = new LayoutGroup(ele.Side, DockMode.Float, DockManager); group.AttachObj = new AttachObject(group, _parent, _index); } //先从逻辑父级中移除 ele.Container.Detach(ele); //再加入新的逻辑父级 group.Attach(ele); //创建新的浮动窗口,并初始化位置 if (ele.IsDocument) { _dragWnd = new DocumentGroupWindow(DockManager); _dragWnd.AttachChild(new LayoutDocumentGroupControl(group), AttachMode.None, 0); _dragWnd.Top = mouseP.Y - _dragItem.ClickPos.Y; _dragWnd.Left = mouseP.X - _dragItem.ClickPos.X - _dragItem.ClickRect.Left - Constants.DocumentWindowPadding; } else { _dragWnd = new AnchorGroupWindow(DockManager) { NeedReCreate = _dragItem.DragMode == DragMode.Anchor }; _dragWnd.AttachChild(new AnchorSideGroupControl(group) { IsDraggingFromDock = _dragItem.DragMode == DragMode.Anchor }, AttachMode.None, 0); if (!_dragWnd.NeedReCreate) { _dragWnd.Top = mouseP.Y - _dragItem.ClickPos.Y; _dragWnd.Left = mouseP.X - _dragItem.ClickPos.X - _dragItem.ClickRect.Left - Constants.DocumentWindowPadding; } else { _dragWnd.Top = mouseP.Y + _dragItem.ClickPos.Y - _dragWnd.Height; _dragWnd.Left = mouseP.X - _dragItem.ClickPos.X - Constants.DocumentWindowPadding; } } if (_dragWnd is DocumentGroupWindow) { _dragWnd.Recreate(); } _dragWnd.Show(); } break; case DockMode.DockBar: //这里表示从自动隐藏窗口进行的拖动,因此这里移除自动隐藏窗口 ele = _dragItem.RelativeObj as IDockElement; ele.Container.Detach(ele); //创建新的浮动窗口,并初始化位置 group = new LayoutGroup(ele.Side, DockMode.Float, DockManager); group.Attach(ele); _dragWnd = new AnchorGroupWindow(DockManager) { Left = mouseP.X - _dragItem.ClickPos.X - 1, Top = mouseP.Y - _dragItem.ClickPos.Y - 1 }; _dragWnd.AttachChild(new AnchorSideGroupControl(group), AttachMode.None, 0); _dragWnd.Show(); break; case DockMode.Float: if (_dragItem.RelativeObj is IDockElement) { ele = _dragItem.RelativeObj as IDockElement; var ctrl = ele.Container.View as BaseGroupControl; if (ctrl.Items.Count == 1 && ctrl.Parent is BaseFloatWindow) { _dragWnd = ctrl.Parent as BaseFloatWindow; _dragWnd.DetachChild(ctrl); _dragWnd.Close(); _dragWnd = new DocumentGroupWindow(DockManager); _dragWnd.AttachChild(ctrl, AttachMode.None, 0); _dragWnd.Top = mouseP.Y - _dragItem.ClickPos.Y; _dragWnd.Left = mouseP.X - _dragItem.ClickPos.X - _dragItem.ClickRect.Left - Constants.DocumentWindowPadding; _dragWnd.Recreate(); _dragWnd.Show(); } else { #region AttachObj var _parent = (ele.Container as LayoutGroup).View as BaseGroupControl; var _index = ele.Container.IndexOf(ele); #endregion if (ele.IsDocument) { group = new LayoutDocumentGroup(DockMode.Float, DockManager); } else { group = new LayoutGroup(ele.Side, DockMode.Float, DockManager); group.AttachObj = new AttachObject(group, _parent, _index); } //先从逻辑父级中移除 ele.Container.Detach(ele); //再加入新的逻辑父级 group.Attach(ele); //创建新的浮动窗口,并初始化位置 //这里可知引起drag的时DragTabItem故这里创建临时的DragTabWindow if (ele.IsDocument) { _dragWnd = new DocumentGroupWindow(DockManager); _dragWnd.AttachChild(new LayoutDocumentGroupControl(group), AttachMode.None, 0); _dragWnd.Top = mouseP.Y - _dragItem.ClickPos.Y; _dragWnd.Left = mouseP.X - _dragItem.ClickPos.X - _dragItem.ClickRect.Left - Constants.DocumentWindowPadding; } else { _dragWnd = new AnchorGroupWindow(DockManager) { NeedReCreate = _dragItem.DragMode == DragMode.Anchor }; _dragWnd.AttachChild(new AnchorSideGroupControl(group) { IsDraggingFromDock = _dragItem.DragMode == DragMode.Anchor }, AttachMode.None, 0); if (!_dragWnd.NeedReCreate) { _dragWnd.Top = mouseP.Y - _dragItem.ClickPos.Y; _dragWnd.Left = mouseP.X - _dragItem.ClickPos.X - _dragItem.ClickRect.Left - Constants.DocumentWindowPadding; } else { _dragWnd.Top = mouseP.Y + _dragItem.ClickPos.Y - _dragWnd.Height; _dragWnd.Left = mouseP.X - _dragItem.ClickPos.X - Constants.DocumentWindowPadding; } } if (_dragWnd is DocumentGroupWindow) { _dragWnd.Recreate(); } _dragWnd.Show(); } } else if (_dragItem.RelativeObj is ILayoutGroup) { group = _dragItem.RelativeObj as LayoutGroup; //表示此时的浮动窗口为IsSingleMode if (group.View.DockViewParent == null) { _dragWnd = (group.View as BaseGroupControl).Parent as BaseFloatWindow; } else { #region AttachObj var _parent = group.View.DockViewParent as LayoutGroupPanel; var _mode = _parent.Direction == Direction.Horizontal ? AttachMode.Left : AttachMode.Top; if (_parent.Direction == Direction.None) { _mode = AttachMode.None; } var _index = _parent.IndexOf(group.View); if (_parent.Children.Count - 1 > _index) { group.AttachObj = new AttachObject(group, _parent.Children[_index + 2] as INotifyDisposable, _index, _mode); } else { group.AttachObj = new AttachObject(group, _parent.Children[_index - 2] as INotifyDisposable, _index, _mode); } #endregion //这里移动的一定是AnchorSideGroup,故将其从父级LayoutGroupPanel移走,但不Dispose留着构造浮动窗口 if ((group.View as ILayoutGroupControl).TryDeatchFromParent(false)) { _dragWnd = new AnchorGroupWindow(DockManager) { Left = mouseP.X - _dragItem.ClickPos.X - 1, Top = mouseP.Y - _dragItem.ClickPos.Y - 1 }; _dragWnd.AttachChild(group.View, AttachMode.None, 0); _dragWnd.Show(); } } } break; } }