void CreateSplitters() { for (int iChild = 1; iChild < Children.Count; iChild++) { var splitter = new LayoutGridResizerControl(); splitter.Cursor = this.Orientation == Orientation.Horizontal ? Cursors.SizeWE : Cursors.SizeNS; Children.Insert(iChild, splitter); iChild++; } }
private void CreateSplitters() { for (int i = 1; i < base.Children.Count; i++) { LayoutGridResizerControl layoutGridResizerControl = new LayoutGridResizerControl() { Cursor = (this.Orientation == System.Windows.Controls.Orientation.Horizontal ? Cursors.SizeWE : Cursors.SizeNS) }; base.Children.Insert(i, layoutGridResizerControl); i++; } }
void OnSplitterDragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) { LayoutGridResizerControl splitter = sender as LayoutGridResizerControl; var rootVisual = this.FindVisualTreeRoot() as Visual; var trToWnd = TransformToAncestor(rootVisual); Vector transformedDelta = trToWnd.Transform(new Point(e.HorizontalChange, e.VerticalChange)) - trToWnd.Transform(new Point()); if (Orientation == System.Windows.Controls.Orientation.Horizontal) { Canvas.SetLeft(_resizerGhost, MathHelper.MinMax(_initialStartPoint.X + transformedDelta.X, 0.0, _resizerWindowHost.Width - _resizerGhost.Width)); } else { Canvas.SetTop(_resizerGhost, MathHelper.MinMax(_initialStartPoint.Y + transformedDelta.Y, 0.0, _resizerWindowHost.Height - _resizerGhost.Height)); } }
void OnResizerDragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) { LayoutGridResizerControl splitter = sender as LayoutGridResizerControl; var rootVisual = this.FindVisualTreeRoot() as Visual; var trToWnd = TransformToAncestor(rootVisual); Vector transformedDelta = trToWnd.Transform(new Point(e.HorizontalChange, e.VerticalChange)) - trToWnd.Transform(new Point()); if (_side == AnchorSide.Right || _side == AnchorSide.Left) { if (FrameworkElement.GetFlowDirection(_internalHost) == System.Windows.FlowDirection.RightToLeft) { transformedDelta.X = -transformedDelta.X; } Canvas.SetLeft(_resizerGhost, MathHelper.MinMax(_initialStartPoint.X + transformedDelta.X, 0.0, _resizerWindowHost.Width - _resizerGhost.Width)); } else { Canvas.SetTop(_resizerGhost, MathHelper.MinMax(_initialStartPoint.Y + transformedDelta.Y, 0.0, _resizerWindowHost.Height - _resizerGhost.Height)); } }
void OnResizerDragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e) { LayoutGridResizerControl splitter = sender as LayoutGridResizerControl; var rootVisual = this.FindVisualTreeRoot() as Visual; var trToWnd = TransformToAncestor(rootVisual); Vector transformedDelta = trToWnd.Transform(new Point(e.HorizontalChange, e.VerticalChange)) - trToWnd.Transform(new Point()); double delta; if (_side == AnchorSide.Right || _side == AnchorSide.Left) { delta = Canvas.GetLeft(_resizerGhost) - _initialStartPoint.X; } else { delta = Canvas.GetTop(_resizerGhost) - _initialStartPoint.Y; } if (_side == AnchorSide.Right) { if (_model.AutoHideWidth == 0.0) { _model.AutoHideWidth = _internalHost.ActualWidth - delta; } else { _model.AutoHideWidth -= delta; } _internalGrid.ColumnDefinitions[1].Width = new GridLength(_model.AutoHideWidth, GridUnitType.Pixel); } else if (_side == AnchorSide.Left) { if (_model.AutoHideWidth == 0.0) { _model.AutoHideWidth = _internalHost.ActualWidth + delta; } else { _model.AutoHideWidth += delta; } _internalGrid.ColumnDefinitions[0].Width = new GridLength(_model.AutoHideWidth, GridUnitType.Pixel); } else if (_side == AnchorSide.Top) { if (_model.AutoHideHeight == 0.0) { _model.AutoHideHeight = _internalHost.ActualHeight + delta; } else { _model.AutoHideHeight += delta; } _internalGrid.RowDefinitions[0].Height = new GridLength(_model.AutoHideHeight, GridUnitType.Pixel); } else if (_side == AnchorSide.Bottom) { if (_model.AutoHideHeight == 0.0) { _model.AutoHideHeight = _internalHost.ActualHeight - delta; } else { _model.AutoHideHeight -= delta; } _internalGrid.RowDefinitions[1].Height = new GridLength(_model.AutoHideHeight, GridUnitType.Pixel); } HideResizerOverlayWindow(); IsResizing = false; InvalidateMeasure(); }
private void OnSplitterDragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e) { LayoutGridResizerControl splitter = sender as LayoutGridResizerControl; var rootVisual = this.FindVisualTreeRoot() as Visual; var trToWnd = TransformToAncestor(rootVisual); Vector transformedDelta = trToWnd.Transform(new Point(e.HorizontalChange, e.VerticalChange)) - trToWnd.Transform(new Point()); double delta; if (Orientation == Orientation.Horizontal) { delta = Canvas.GetLeft(_resizerGhost) - _initialStartPoint.X; } else { delta = Canvas.GetTop(_resizerGhost) - _initialStartPoint.Y; } int indexOfResizer = InternalChildren.IndexOf(splitter); var prevChild = InternalChildren[indexOfResizer - 1] as FrameworkElement; var nextChild = GetNextVisibleChild(indexOfResizer); var prevChildActualSize = prevChild.TransformActualSizeToAncestor(); var nextChildActualSize = (nextChild != null) ? nextChild.TransformActualSizeToAncestor() : new Size(); var totalActualSize = new Size(prevChildActualSize.Width + nextChildActualSize.Width, prevChildActualSize.Height + nextChildActualSize.Height); var prevChildModel = ( ILayoutPositionableElement )(prevChild as ILayoutControl).Model; var nextChildModel = (nextChild != null) ? ( ILayoutPositionableElement )(nextChild as ILayoutControl).Model : null; var totalStarSize = new Size(prevChildModel.DockWidth.IsStar && nextChildModel.DockWidth.IsStar ? prevChildModel.DockWidth.Value + nextChildModel.DockWidth.Value : 1d, prevChildModel.DockHeight.IsStar && nextChildModel.DockHeight.IsStar ? prevChildModel.DockHeight.Value + nextChildModel.DockHeight.Value : 1d); if (Orientation == Orientation.Horizontal) { if (prevChildModel.DockWidth.IsStar) { prevChildModel.DockWidth = new GridLength(((prevChildActualSize.Width + delta) / totalActualSize.Width) * totalStarSize.Width, GridUnitType.Star); } else { var width = (prevChildModel.DockWidth.IsAuto) ? prevChildActualSize.Width : prevChildModel.DockWidth.Value; width += delta; var widthToSet = Math.Max(width, prevChildModel.DockMinWidth); prevChildModel.DockWidth = new GridLength(widthToSet, GridUnitType.Pixel); } if (nextChildModel != null) { if (nextChildModel.DockWidth.IsStar) { nextChildModel.DockWidth = new GridLength(((nextChildActualSize.Width - delta) / totalActualSize.Width) * totalStarSize.Width, GridUnitType.Star); } else { var width = (nextChildModel.DockWidth.IsAuto) ? nextChildActualSize.Width : nextChildModel.DockWidth.Value; width -= delta; var widthToSet = Math.Max(width, nextChildModel.DockMinWidth); nextChildModel.DockWidth = new GridLength(widthToSet, GridUnitType.Pixel); } } } else { if (prevChildModel.DockHeight.IsStar) { prevChildModel.DockHeight = new GridLength(((prevChildActualSize.Height + delta) / totalActualSize.Height) * totalStarSize.Height, GridUnitType.Star); } else { var height = (prevChildModel.DockHeight.IsAuto) ? prevChildActualSize.Height : prevChildModel.DockHeight.Value; height += delta; var heightToSet = Math.Max(height, prevChildModel.DockMinHeight); prevChildModel.DockHeight = new GridLength(heightToSet, GridUnitType.Pixel); } if (nextChildModel != null) { if (nextChildModel.DockHeight.IsStar) { nextChildModel.DockHeight = new GridLength(((nextChildActualSize.Height - delta) / totalActualSize.Height) * totalStarSize.Height, GridUnitType.Star); } else { var height = (nextChildModel.DockHeight.IsAuto) ? nextChildActualSize.Height : nextChildModel.DockHeight.Value; height -= delta; var heightToSet = Math.Max(height, nextChildModel.DockMinHeight); nextChildModel.DockHeight = new GridLength(heightToSet, GridUnitType.Pixel); } } } HideResizerOverlayWindow(); }
void CreateInternalGrid() { _internalGrid = new Grid() { FlowDirection = System.Windows.FlowDirection.LeftToRight }; _internalGrid.SetBinding(Grid.BackgroundProperty, new Binding("Background") { Source = this }); _internalHost = new LayoutAnchorableControl() { Model = _model, Style = AnchorableStyle }; _internalHost.SetBinding(FlowDirectionProperty, new Binding("Model.Root.Manager.FlowDirection") { Source = this }); KeyboardNavigation.SetTabNavigation(_internalGrid, KeyboardNavigationMode.Cycle); _resizer = new LayoutGridResizerControl(); _resizer.DragStarted += new System.Windows.Controls.Primitives.DragStartedEventHandler(OnResizerDragStarted); _resizer.DragDelta += new System.Windows.Controls.Primitives.DragDeltaEventHandler(OnResizerDragDelta); _resizer.DragCompleted += new System.Windows.Controls.Primitives.DragCompletedEventHandler(OnResizerDragCompleted); if (_side == AnchorSide.Right) { _internalGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(_manager.GridSplitterWidth) }); _internalGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = _model.AutoHideWidth == 0.0 ? new GridLength(_model.AutoHideMinWidth) : new GridLength(_model.AutoHideWidth, GridUnitType.Pixel) }); Grid.SetColumn(_resizer, 0); Grid.SetColumn(_internalHost, 1); _resizer.Cursor = Cursors.SizeWE; HorizontalAlignment = System.Windows.HorizontalAlignment.Right; VerticalAlignment = System.Windows.VerticalAlignment.Stretch; } else if (_side == AnchorSide.Left) { _internalGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = _model.AutoHideWidth == 0.0 ? new GridLength(_model.AutoHideMinWidth) : new GridLength(_model.AutoHideWidth, GridUnitType.Pixel), }); _internalGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(_manager.GridSplitterWidth) }); Grid.SetColumn(_internalHost, 0); Grid.SetColumn(_resizer, 1); _resizer.Cursor = Cursors.SizeWE; HorizontalAlignment = System.Windows.HorizontalAlignment.Left; VerticalAlignment = System.Windows.VerticalAlignment.Stretch; } else if (_side == AnchorSide.Top) { _internalGrid.RowDefinitions.Add(new RowDefinition() { Height = _model.AutoHideHeight == 0.0 ? new GridLength(_model.AutoHideMinHeight) : new GridLength(_model.AutoHideHeight, GridUnitType.Pixel), }); _internalGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(_manager.GridSplitterHeight) }); Grid.SetRow(_internalHost, 0); Grid.SetRow(_resizer, 1); _resizer.Cursor = Cursors.SizeNS; VerticalAlignment = System.Windows.VerticalAlignment.Top; HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; } else if (_side == AnchorSide.Bottom) { _internalGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(_manager.GridSplitterHeight) }); _internalGrid.RowDefinitions.Add(new RowDefinition() { Height = _model.AutoHideHeight == 0.0 ? new GridLength(_model.AutoHideMinHeight) : new GridLength(_model.AutoHideHeight, GridUnitType.Pixel), }); Grid.SetRow(_resizer, 0); Grid.SetRow(_internalHost, 1); _resizer.Cursor = Cursors.SizeNS; VerticalAlignment = System.Windows.VerticalAlignment.Bottom; HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; } _internalGrid.Children.Add(_resizer); _internalGrid.Children.Add(_internalHost); _internalHostPresenter.Content = _internalGrid; }
void ShowResizerOverlayWindow(LayoutGridResizerControl splitter) { _resizerGhost = new Border() { Background = splitter.BackgroundWhileDragging, Opacity = splitter.OpacityWhileDragging }; var areaElement = _manager.GetAutoHideAreaElement(); var modelControlActualSize = this._internalHost.TransformActualSizeToAncestor(); Point ptTopLeftScreen = areaElement.PointToScreenDPIWithoutFlowDirection(new Point()); var managerSize = areaElement.TransformActualSizeToAncestor(); Size windowSize; if (_side == AnchorSide.Right || _side == AnchorSide.Left) { windowSize = new Size( managerSize.Width - 25.0 + splitter.ActualWidth, managerSize.Height); _resizerGhost.Width = splitter.ActualWidth; _resizerGhost.Height = windowSize.Height; ptTopLeftScreen.Offset(25, 0.0); } else { windowSize = new Size( managerSize.Width, managerSize.Height - _model.AutoHideMinHeight - 25.0 + splitter.ActualHeight); _resizerGhost.Height = splitter.ActualHeight; _resizerGhost.Width = windowSize.Width; ptTopLeftScreen.Offset(0.0, 25.0); } _initialStartPoint = splitter.PointToScreenDPIWithoutFlowDirection(new Point()) - ptTopLeftScreen; if (_side == AnchorSide.Right || _side == AnchorSide.Left) { Canvas.SetLeft(_resizerGhost, _initialStartPoint.X); } else { Canvas.SetTop(_resizerGhost, _initialStartPoint.Y); } Canvas panelHostResizer = new Canvas() { HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch, VerticalAlignment = System.Windows.VerticalAlignment.Stretch }; panelHostResizer.Children.Add(_resizerGhost); _resizerWindowHost = new Window() { ResizeMode = ResizeMode.NoResize, WindowStyle = System.Windows.WindowStyle.None, ShowInTaskbar = false, AllowsTransparency = true, Background = null, Width = windowSize.Width, Height = windowSize.Height, Left = ptTopLeftScreen.X, Top = ptTopLeftScreen.Y, ShowActivated = false, Owner = Window.GetWindow(this), Content = panelHostResizer }; _resizerWindowHost.Show(); }
void CreateInternalGrid() { _internalGrid = new Grid() { FlowDirection = System.Windows.FlowDirection.LeftToRight}; _internalGrid.SetBinding(Grid.BackgroundProperty, new Binding("Background") { Source = this }); _internalHost = new LayoutAnchorableControl() { Model = _model, Style = AnchorableStyle }; _internalHost.SetBinding(FlowDirectionProperty, new Binding("Model.Root.Manager.FlowDirection") { Source = this }); KeyboardNavigation.SetTabNavigation(_internalGrid, KeyboardNavigationMode.Cycle); _resizer = new LayoutGridResizerControl(); _resizer.DragStarted += new System.Windows.Controls.Primitives.DragStartedEventHandler(OnResizerDragStarted); _resizer.DragDelta += new System.Windows.Controls.Primitives.DragDeltaEventHandler(OnResizerDragDelta); _resizer.DragCompleted += new System.Windows.Controls.Primitives.DragCompletedEventHandler(OnResizerDragCompleted); if (_side == AnchorSide.Right) { _internalGrid.ColumnDefinitions.Add(new ColumnDefinition(){ Width = new GridLength(_manager.GridSplitterWidth)}); _internalGrid.ColumnDefinitions.Add(new ColumnDefinition(){ Width = _model.AutoHideWidth == 0.0 ? new GridLength(_model.AutoHideMinWidth) : new GridLength(_model.AutoHideWidth, GridUnitType.Pixel)}); Grid.SetColumn(_resizer, 0); Grid.SetColumn(_internalHost, 1); _resizer.Cursor = Cursors.SizeWE; HorizontalAlignment = System.Windows.HorizontalAlignment.Right; VerticalAlignment = System.Windows.VerticalAlignment.Stretch; } else if (_side == AnchorSide.Left) { _internalGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = _model.AutoHideWidth == 0.0 ? new GridLength(_model.AutoHideMinWidth) : new GridLength(_model.AutoHideWidth, GridUnitType.Pixel), }); _internalGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(_manager.GridSplitterWidth) }); Grid.SetColumn(_internalHost, 0); Grid.SetColumn(_resizer, 1); _resizer.Cursor = Cursors.SizeWE; HorizontalAlignment = System.Windows.HorizontalAlignment.Left; VerticalAlignment = System.Windows.VerticalAlignment.Stretch; } else if (_side == AnchorSide.Top) { _internalGrid.RowDefinitions.Add(new RowDefinition() { Height = _model.AutoHideHeight == 0.0 ? new GridLength(_model.AutoHideMinHeight) : new GridLength(_model.AutoHideHeight, GridUnitType.Pixel), }); _internalGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(_manager.GridSplitterHeight) }); Grid.SetRow(_internalHost, 0); Grid.SetRow(_resizer, 1); _resizer.Cursor = Cursors.SizeNS; VerticalAlignment = System.Windows.VerticalAlignment.Top; HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; } else if (_side == AnchorSide.Bottom) { _internalGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(_manager.GridSplitterHeight) }); _internalGrid.RowDefinitions.Add(new RowDefinition() { Height = _model.AutoHideHeight == 0.0 ? new GridLength(_model.AutoHideMinHeight) : new GridLength(_model.AutoHideHeight, GridUnitType.Pixel), }); Grid.SetRow(_resizer, 0); Grid.SetRow(_internalHost, 1); _resizer.Cursor = Cursors.SizeNS; VerticalAlignment = System.Windows.VerticalAlignment.Bottom; HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; } _internalGrid.Children.Add(_resizer); _internalGrid.Children.Add(_internalHost); _internalHostPresenter.Content = _internalGrid; }
void OnSplitterDragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e) { LayoutGridResizerControl splitter = sender as LayoutGridResizerControl; var rootVisual = this.FindVisualTreeRoot() as Visual; var trToWnd = TransformToAncestor(rootVisual); Vector transformedDelta = trToWnd.Transform(new Point(e.HorizontalChange, e.VerticalChange)) - trToWnd.Transform(new Point()); double delta; if (Orientation == System.Windows.Controls.Orientation.Horizontal) { delta = Canvas.GetLeft(_resizerGhost) - _initialStartPoint.X; } else { delta = Canvas.GetTop(_resizerGhost) - _initialStartPoint.Y; } int indexOfResizer = InternalChildren.IndexOf(splitter); var prevChild = InternalChildren[indexOfResizer - 1] as FrameworkElement; var nextChild = GetNextVisibleChild(indexOfResizer); var prevChildActualSize = prevChild.TransformActualSizeToAncestor(); var nextChildActualSize = nextChild.TransformActualSizeToAncestor(); var prevChildModel = (ILayoutPositionableElement)(prevChild as ILayoutControl).Model; var nextChildModel = (ILayoutPositionableElement)(nextChild as ILayoutControl).Model; if (Orientation == System.Windows.Controls.Orientation.Horizontal) { //Trace.WriteLine(string.Format("PrevChild From {0}", prevChildModel.DockWidth)); if (prevChildModel.DockWidth.IsAuto) { prevChildModel.DockWidth = new GridLength(prevChildActualSize.Width + delta, GridUnitType.Pixel); } else if (prevChildModel.DockWidth.IsStar) { prevChildModel.DockWidth = new GridLength(prevChildModel.DockWidth.Value * (prevChildActualSize.Width + delta) / prevChildActualSize.Width, GridUnitType.Star); } else { prevChildModel.DockWidth = new GridLength(prevChildModel.DockWidth.Value + delta, GridUnitType.Pixel); } //Trace.WriteLine(string.Format("PrevChild To {0}", prevChildModel.DockWidth)); //Trace.WriteLine(string.Format("NextChild From {0}", nextChildModel.DockWidth)); if (nextChildModel.DockWidth.IsAuto) { nextChildModel.DockWidth = new GridLength(nextChildActualSize.Width - delta, GridUnitType.Pixel); } else if (nextChildModel.DockWidth.IsStar) { nextChildModel.DockWidth = new GridLength(nextChildModel.DockWidth.Value * (nextChildActualSize.Width - delta) / nextChildActualSize.Width, GridUnitType.Star); } else { nextChildModel.DockWidth = new GridLength(nextChildModel.DockWidth.Value - delta, GridUnitType.Pixel); } //Trace.WriteLine(string.Format("NextChild To {0}", nextChildModel.DockWidth)); } else { //Trace.WriteLine(string.Format("PrevChild From {0}", prevChildModel.DockHeight)); if (prevChildModel.DockHeight.IsAuto) { prevChildModel.DockHeight = new GridLength(prevChildActualSize.Height + delta, GridUnitType.Pixel); } else if (prevChildModel.DockHeight.IsStar) { prevChildModel.DockHeight = new GridLength(prevChildModel.DockHeight.Value * (prevChildActualSize.Height + delta) / prevChildActualSize.Height, GridUnitType.Star); } else { prevChildModel.DockHeight = new GridLength(prevChildModel.DockHeight.Value + delta, GridUnitType.Pixel); } //Trace.WriteLine(string.Format("PrevChild To {0}", prevChildModel.DockHeight)); //Trace.WriteLine(string.Format("NextChild From {0}", nextChildModel.DockHeight)); if (nextChildModel.DockHeight.IsAuto) { nextChildModel.DockHeight = new GridLength(nextChildActualSize.Height - delta, GridUnitType.Pixel); } else if (nextChildModel.DockHeight.IsStar) { nextChildModel.DockHeight = new GridLength(nextChildModel.DockHeight.Value * (nextChildActualSize.Height - delta) / nextChildActualSize.Height, GridUnitType.Star); } else { nextChildModel.DockHeight = new GridLength(nextChildModel.DockHeight.Value - delta, GridUnitType.Pixel); } //Trace.WriteLine(string.Format("NextChild To {0}", nextChildModel.DockHeight)); } HideResizerOverlayWindow(); var manager = _model.Root.Manager; if (manager != null) { manager.OnLayoutConfigurationChanged(); } }
void ShowResizerOverlayWindow(LayoutGridResizerControl splitter) { _resizerGhost = new Border() { Background = splitter.BackgroundWhileDragging, Opacity = splitter.OpacityWhileDragging }; int indexOfResizer = InternalChildren.IndexOf(splitter); var prevChild = InternalChildren[indexOfResizer - 1] as FrameworkElement; var nextChild = GetNextVisibleChild(indexOfResizer); var prevChildActualSize = prevChild.TransformActualSizeToAncestor(); var nextChildActualSize = nextChild.TransformActualSizeToAncestor(); var prevChildModel = (ILayoutPositionableElement)(prevChild as ILayoutControl).Model; var nextChildModel = (ILayoutPositionableElement)(nextChild as ILayoutControl).Model; Point ptTopLeftScreen = prevChild.PointToScreenDPIWithoutFlowDirection(new Point()); Size actualSize; if (Orientation == System.Windows.Controls.Orientation.Horizontal) { actualSize = new Size( prevChildActualSize.Width - prevChildModel.DockMinWidth + splitter.ActualWidth + nextChildActualSize.Width - nextChildModel.DockMinWidth, nextChildActualSize.Height); _resizerGhost.Width = splitter.ActualWidth; _resizerGhost.Height = actualSize.Height; ptTopLeftScreen.Offset(prevChildModel.DockMinWidth, 0.0); } else { actualSize = new Size( prevChildActualSize.Width, prevChildActualSize.Height - prevChildModel.DockMinHeight + splitter.ActualHeight + nextChildActualSize.Height - nextChildModel.DockMinHeight); _resizerGhost.Height = splitter.ActualHeight; _resizerGhost.Width = actualSize.Width; ptTopLeftScreen.Offset(0.0, prevChildModel.DockMinHeight); } _initialStartPoint = splitter.PointToScreenDPIWithoutFlowDirection(new Point()) - ptTopLeftScreen; if (Orientation == System.Windows.Controls.Orientation.Horizontal) { Canvas.SetLeft(_resizerGhost, _initialStartPoint.X); } else { Canvas.SetTop(_resizerGhost, _initialStartPoint.Y); } Canvas panelHostResizer = new Canvas() { HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch, VerticalAlignment = System.Windows.VerticalAlignment.Stretch }; panelHostResizer.Children.Add(_resizerGhost); _resizerWindowHost = new Window() { SizeToContent = System.Windows.SizeToContent.Manual, ResizeMode = ResizeMode.NoResize, WindowStyle = System.Windows.WindowStyle.None, ShowInTaskbar = false, AllowsTransparency = true, Background = null, Width = actualSize.Width, Height = actualSize.Height, Left = ptTopLeftScreen.X, Top = ptTopLeftScreen.Y, ShowActivated = false, //Owner = Window.GetWindow(this), Content = panelHostResizer }; _resizerWindowHost.Loaded += (s, e) => { _resizerWindowHost.SetParentToMainWindowOf(this); }; _resizerWindowHost.Show(); }
private void CreateInternalGrid() { this._internalGrid = new Grid() { FlowDirection = System.Windows.FlowDirection.LeftToRight }; this._internalGrid.SetBinding(Panel.BackgroundProperty, new Binding("Background") { Source = this }); this._internalHost = new LayoutAnchorableControl() { Model = this._model, Style = this.AnchorableStyle }; this._internalHost.SetBinding(FrameworkElement.FlowDirectionProperty, new Binding("Model.Root.Manager.FlowDirection") { Source = this }); System.Windows.Input.KeyboardNavigation.SetTabNavigation(this._internalGrid, KeyboardNavigationMode.Cycle); this._resizer = new LayoutGridResizerControl(); this._resizer.DragStarted += new DragStartedEventHandler(this.OnResizerDragStarted); this._resizer.DragDelta += new DragDeltaEventHandler(this.OnResizerDragDelta); this._resizer.DragCompleted += new DragCompletedEventHandler(this.OnResizerDragCompleted); if (this._side == AnchorSide.Right) { this._internalGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(this._manager.GridSplitterWidth) }); this._internalGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = (this._model.AutoHideWidth == 0 ? new GridLength(this._model.AutoHideMinWidth) : new GridLength(this._model.AutoHideWidth, GridUnitType.Pixel)) }); Grid.SetColumn(this._resizer, 0); Grid.SetColumn(this._internalHost, 1); this._resizer.Cursor = Cursors.SizeWE; base.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; base.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; } else if (this._side == AnchorSide.Left) { this._internalGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = (this._model.AutoHideWidth == 0 ? new GridLength(this._model.AutoHideMinWidth) : new GridLength(this._model.AutoHideWidth, GridUnitType.Pixel)) }); this._internalGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(this._manager.GridSplitterWidth) }); Grid.SetColumn(this._internalHost, 0); Grid.SetColumn(this._resizer, 1); this._resizer.Cursor = Cursors.SizeWE; base.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; base.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; } else if (this._side == AnchorSide.Top) { this._internalGrid.RowDefinitions.Add(new RowDefinition() { Height = (this._model.AutoHideHeight == 0 ? new GridLength(this._model.AutoHideMinHeight) : new GridLength(this._model.AutoHideHeight, GridUnitType.Pixel)) }); this._internalGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(this._manager.GridSplitterHeight) }); Grid.SetRow(this._internalHost, 0); Grid.SetRow(this._resizer, 1); this._resizer.Cursor = Cursors.SizeNS; base.VerticalAlignment = System.Windows.VerticalAlignment.Top; base.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; } else if (this._side == AnchorSide.Bottom) { this._internalGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(this._manager.GridSplitterHeight) }); this._internalGrid.RowDefinitions.Add(new RowDefinition() { Height = (this._model.AutoHideHeight == 0 ? new GridLength(this._model.AutoHideMinHeight) : new GridLength(this._model.AutoHideHeight, GridUnitType.Pixel)) }); Grid.SetRow(this._resizer, 0); Grid.SetRow(this._internalHost, 1); this._resizer.Cursor = Cursors.SizeNS; base.VerticalAlignment = System.Windows.VerticalAlignment.Bottom; base.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; } this._internalGrid.Children.Add(this._resizer); this._internalGrid.Children.Add(this._internalHost); this._internalHostPresenter.Content = this._internalGrid; }
private void ShowResizerOverlayWindow(LayoutGridResizerControl splitter) { Size size; this._resizerGhost = new Border() { Background = splitter.BackgroundWhileDragging, Opacity = splitter.OpacityWhileDragging }; FrameworkElement autoHideAreaElement = this._manager.GetAutoHideAreaElement(); this._internalHost.TransformActualSizeToAncestor(); Point point = new Point(); Point screenDPIWithoutFlowDirection = autoHideAreaElement.PointToScreenDPIWithoutFlowDirection(point); Size ancestor = autoHideAreaElement.TransformActualSizeToAncestor(); if (this._side == AnchorSide.Right || this._side == AnchorSide.Left) { size = new Size(ancestor.Width - 25 + splitter.ActualWidth, ancestor.Height); this._resizerGhost.Width = splitter.ActualWidth; this._resizerGhost.Height = size.Height; screenDPIWithoutFlowDirection.Offset(25, 0); } else { size = new Size(ancestor.Width, ancestor.Height - this._model.AutoHideMinHeight - 25 + splitter.ActualHeight); this._resizerGhost.Height = splitter.ActualHeight; this._resizerGhost.Width = size.Width; screenDPIWithoutFlowDirection.Offset(0, 25); } point = new Point(); this._initialStartPoint = splitter.PointToScreenDPIWithoutFlowDirection(point) - screenDPIWithoutFlowDirection; if (this._side == AnchorSide.Right || this._side == AnchorSide.Left) { Canvas.SetLeft(this._resizerGhost, this._initialStartPoint.X); } else { Canvas.SetTop(this._resizerGhost, this._initialStartPoint.Y); } Canvas canva = new Canvas() { HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch, VerticalAlignment = System.Windows.VerticalAlignment.Stretch }; canva.Children.Add(this._resizerGhost); this._resizerWindowHost = new Window() { ResizeMode = ResizeMode.NoResize, WindowStyle = WindowStyle.None, ShowInTaskbar = false, AllowsTransparency = true, Background = null, Width = size.Width, Height = size.Height, Left = screenDPIWithoutFlowDirection.X, Top = screenDPIWithoutFlowDirection.Y, ShowActivated = false, Owner = Window.GetWindow(this), Content = canva }; this._resizerWindowHost.Show(); }
private void OnSplitterDragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e) { LayoutGridResizerControl splitter = sender as LayoutGridResizerControl; var rootVisual = this.FindVisualTreeRoot() as Visual; var trToWnd = TransformToAncestor(rootVisual); Vector transformedDelta = trToWnd.Transform(new Point(e.HorizontalChange, e.VerticalChange)) - trToWnd.Transform(new Point()); double delta; if (Orientation == System.Windows.Controls.Orientation.Horizontal) { delta = Canvas.GetLeft(_resizerGhost) - _initialStartPoint.X; } else { delta = Canvas.GetTop(_resizerGhost) - _initialStartPoint.Y; } int indexOfResizer = InternalChildren.IndexOf(splitter); var prevChild = InternalChildren[indexOfResizer - 1] as FrameworkElement; var nextChild = GetNextVisibleChild(indexOfResizer); var prevChildActualSize = prevChild.TransformActualSizeToAncestor(); var nextChildActualSize = nextChild.TransformActualSizeToAncestor(); var prevChildModel = ( ILayoutPositionableElement )(prevChild as ILayoutControl).Model; var nextChildModel = ( ILayoutPositionableElement )(nextChild as ILayoutControl).Model; if (Orientation == System.Windows.Controls.Orientation.Horizontal) { if (prevChildModel.DockWidth.IsStar) { prevChildModel.DockWidth = new GridLength(prevChildModel.DockWidth.Value * (prevChildActualSize.Width + delta) / prevChildActualSize.Width, GridUnitType.Star); } else { var width = (prevChildModel.DockWidth.IsAuto) ? prevChildActualSize.Width : prevChildModel.DockWidth.Value; var resizedWidth = width + delta; prevChildModel.DockWidth = new GridLength(double.IsNaN(resizedWidth) ? width : resizedWidth, GridUnitType.Pixel); } if (nextChildModel.DockWidth.IsStar) { nextChildModel.DockWidth = new GridLength(nextChildModel.DockWidth.Value * (nextChildActualSize.Width - delta) / nextChildActualSize.Width, GridUnitType.Star); } else { var width = (nextChildModel.DockWidth.IsAuto) ? nextChildActualSize.Width : nextChildModel.DockWidth.Value; var resizedWidth = width - delta; nextChildModel.DockWidth = new GridLength(double.IsNaN(resizedWidth) ? width : resizedWidth, GridUnitType.Pixel); } } else { if (prevChildModel.DockHeight.IsStar) { prevChildModel.DockHeight = new GridLength(prevChildModel.DockHeight.Value * (prevChildActualSize.Height + delta) / prevChildActualSize.Height, GridUnitType.Star); } else { var height = (prevChildModel.DockHeight.IsAuto) ? prevChildActualSize.Height : prevChildModel.DockHeight.Value; var resizedHeight = height + delta; prevChildModel.DockHeight = new GridLength(double.IsNaN(resizedHeight) ? height : resizedHeight, GridUnitType.Pixel); } if (nextChildModel.DockHeight.IsStar) { nextChildModel.DockHeight = new GridLength(nextChildModel.DockHeight.Value * (nextChildActualSize.Height - delta) / nextChildActualSize.Height, GridUnitType.Star); } else { var height = (nextChildModel.DockHeight.IsAuto) ? nextChildActualSize.Height : nextChildModel.DockHeight.Value; var resizedHeight = height - delta; nextChildModel.DockHeight = new GridLength(double.IsNaN(resizedHeight) ? height : resizedHeight, GridUnitType.Pixel); } } HideResizerOverlayWindow(); }
private void OnSplitterDragCompleted(object sender, DragCompletedEventArgs e) { double num; GridLength dockHeight; LayoutGridResizerControl layoutGridResizerControl = sender as LayoutGridResizerControl; GeneralTransform ancestor = base.TransformToAncestor(this.FindVisualTreeRoot() as Visual); Vector vector = ancestor.Transform(new Point(e.HorizontalChange, e.VerticalChange)) - ancestor.Transform(new Point()); num = (this.Orientation != System.Windows.Controls.Orientation.Horizontal ? Canvas.GetTop(this._resizerGhost) - this._initialStartPoint.Y : Canvas.GetLeft(this._resizerGhost) - this._initialStartPoint.X); int num1 = base.InternalChildren.IndexOf(layoutGridResizerControl); FrameworkElement item = base.InternalChildren[num1 - 1] as FrameworkElement; FrameworkElement nextVisibleChild = this.GetNextVisibleChild(num1); Size size = item.TransformActualSizeToAncestor(); Size ancestor1 = nextVisibleChild.TransformActualSizeToAncestor(); ILayoutPositionableElement model = (ILayoutPositionableElement)(item as ILayoutControl).Model; ILayoutPositionableElement gridLength = (ILayoutPositionableElement)(nextVisibleChild as ILayoutControl).Model; if (this.Orientation != System.Windows.Controls.Orientation.Horizontal) { if (!model.DockHeight.IsStar) { dockHeight = model.DockHeight; model.DockHeight = new GridLength(dockHeight.Value + num, GridUnitType.Pixel); } else { dockHeight = model.DockHeight; model.DockHeight = new GridLength(dockHeight.Value * (size.Height + num) / size.Height, GridUnitType.Star); } if (!gridLength.DockHeight.IsStar) { dockHeight = gridLength.DockHeight; gridLength.DockHeight = new GridLength(dockHeight.Value - num, GridUnitType.Pixel); } else { dockHeight = gridLength.DockHeight; gridLength.DockHeight = new GridLength(dockHeight.Value * (ancestor1.Height - num) / ancestor1.Height, GridUnitType.Star); } } else { if (!model.DockWidth.IsStar) { dockHeight = model.DockWidth; model.DockWidth = new GridLength(dockHeight.Value + num, GridUnitType.Pixel); } else { dockHeight = model.DockWidth; model.DockWidth = new GridLength(dockHeight.Value * (size.Width + num) / size.Width, GridUnitType.Star); } if (!gridLength.DockWidth.IsStar) { dockHeight = gridLength.DockWidth; gridLength.DockWidth = new GridLength(dockHeight.Value - num, GridUnitType.Pixel); } else { dockHeight = gridLength.DockWidth; gridLength.DockWidth = new GridLength(dockHeight.Value * (ancestor1.Width - num) / ancestor1.Width, GridUnitType.Star); } } this.HideResizerOverlayWindow(); }
private void ShowResizerOverlayWindow(LayoutGridResizerControl splitter) { Size size; this._resizerGhost = new Border() { Background = splitter.BackgroundWhileDragging, Opacity = splitter.OpacityWhileDragging }; int num = base.InternalChildren.IndexOf(splitter); FrameworkElement item = base.InternalChildren[num - 1] as FrameworkElement; FrameworkElement nextVisibleChild = this.GetNextVisibleChild(num); Size ancestor = item.TransformActualSizeToAncestor(); Size ancestor1 = nextVisibleChild.TransformActualSizeToAncestor(); ILayoutPositionableElement model = (ILayoutPositionableElement)(item as ILayoutControl).Model; ILayoutPositionableElement layoutPositionableElement = (ILayoutPositionableElement)(nextVisibleChild as ILayoutControl).Model; Point point = new Point(); Point screenDPIWithoutFlowDirection = item.PointToScreenDPIWithoutFlowDirection(point); if (this.Orientation != System.Windows.Controls.Orientation.Horizontal) { size = new Size(ancestor.Width, ancestor.Height - model.DockMinHeight + splitter.ActualHeight + ancestor1.Height - layoutPositionableElement.DockMinHeight); this._resizerGhost.Height = splitter.ActualHeight; this._resizerGhost.Width = size.Width; screenDPIWithoutFlowDirection.Offset(0, model.DockMinHeight); } else { size = new Size(ancestor.Width - model.DockMinWidth + splitter.ActualWidth + ancestor1.Width - layoutPositionableElement.DockMinWidth, ancestor1.Height); this._resizerGhost.Width = splitter.ActualWidth; this._resizerGhost.Height = size.Height; screenDPIWithoutFlowDirection.Offset(model.DockMinWidth, 0); } point = new Point(); this._initialStartPoint = splitter.PointToScreenDPIWithoutFlowDirection(point) - screenDPIWithoutFlowDirection; if (this.Orientation != System.Windows.Controls.Orientation.Horizontal) { Canvas.SetTop(this._resizerGhost, this._initialStartPoint.Y); } else { Canvas.SetLeft(this._resizerGhost, this._initialStartPoint.X); } Canvas canva = new Canvas() { HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch, VerticalAlignment = System.Windows.VerticalAlignment.Stretch }; canva.Children.Add(this._resizerGhost); this._resizerWindowHost = new Window() { SizeToContent = SizeToContent.Manual, ResizeMode = ResizeMode.NoResize, WindowStyle = WindowStyle.None, ShowInTaskbar = false, AllowsTransparency = true, Background = null, Width = size.Width, Height = size.Height, Left = screenDPIWithoutFlowDirection.X, Top = screenDPIWithoutFlowDirection.Y, ShowActivated = false, Content = canva }; this._resizerWindowHost.Loaded += new RoutedEventHandler((object s, RoutedEventArgs e) => this._resizerWindowHost.SetParentToMainWindowOf(this)); this._resizerWindowHost.Show(); }