private void OnDragStarted() { if (!(this.VisualParent is SplitContainer splitContainer)) { return; } var adornerLayer = AdornerLayer.GetAdornerLayer(splitContainer); if (adornerLayer == null) { return; } resizeData = new ResizeData { BeforeElementSize = Orientation == Orientation.Horizontal ? LayoutInformation.GetLayoutSlot(BeforeElement).Height : LayoutInformation.GetLayoutSlot(BeforeElement).Width, AfterElementSize = Orientation == Orientation.Horizontal ? LayoutInformation.GetLayoutSlot(AfterElement).Height : LayoutInformation.GetLayoutSlot(AfterElement).Width, MinOffset = resizeData.BeforeElementSize - 22.0, MaxOffset = resizeData.AfterElementSize - 22.0, PreviewAdorner = new SplitPreviewAdorner(this) }; adornerLayer.Add(this.resizeData.PreviewAdorner); }
private void OnDragCompleted(DragCompletedEventArgs e) { if (resizeData != null) { if (!e.Canceled) { switch (resizeData.SplitterDockSide) { case Dock.Right: resizeData.Parent.ContentSize = Math.Max(this.resizeData.Parent.ContentSize - this.resizeData.PreviewAdorner.OffsetX, 15.0); break; case Dock.Left: resizeData.Parent.ContentSize = Math.Max(this.resizeData.Parent.ContentSize + this.resizeData.PreviewAdorner.OffsetX, 15.0); break; case Dock.Top: resizeData.Parent.ContentSize = Math.Max(this.resizeData.Parent.ContentSize + this.resizeData.PreviewAdorner.OffsetY, 15.0); break; default: resizeData.Parent.ContentSize = Math.Max(this.resizeData.Parent.ContentSize - this.resizeData.PreviewAdorner.OffsetY, 15.0); break; } } if (VisualTreeHelper.GetParent(resizeData.PreviewAdorner) is AdornerLayer adornerLayer) { adornerLayer.Remove(resizeData.PreviewAdorner); } resizeData = null; } }
private void OnDragCompleted(DragCompletedEventArgs e) { if (resizeData != null) { if (!e.Canceled) { Size beforeElementSize = SplitContainer.GetWorkingSize(BeforeElement); Size afterElementSize = SplitContainer.GetWorkingSize(AfterElement); double totalElementSize = beforeElementSize.Height + afterElementSize.Height; double originalElementsTotalSize = this.resizeData.BeforeElementSize + resizeData.AfterElementSize; if (Orientation == Orientation.Horizontal) { double delta = resizeData.PreviewAdorner.OffsetY / originalElementsTotalSize * totalElementSize; SplitContainer.SetWorkingSize(BeforeElement, new Size(beforeElementSize.Width, beforeElementSize.Height + delta)); SplitContainer.SetWorkingSize(AfterElement, new Size(afterElementSize.Width, afterElementSize.Height - delta)); } else { double delta = this.resizeData.PreviewAdorner.OffsetX / originalElementsTotalSize * totalElementSize; SplitContainer.SetWorkingSize(BeforeElement, new Size(beforeElementSize.Width + delta, beforeElementSize.Height)); SplitContainer.SetWorkingSize(AfterElement, new Size(afterElementSize.Width - delta, afterElementSize.Height)); } } if (VisualTreeHelper.GetParent(resizeData.PreviewAdorner) is AdornerLayer adornerLayer) { adornerLayer.Remove(resizeData.PreviewAdorner); } resizeData = null; } }
// Initialize the data needed for resizing private void InitializeData(bool ShowsPreview) { Grid grid = Parent as Grid; // If not in a grid or can't resize, do nothing if (grid != null) { // Setup data used for resizing _resizeData = new ResizeData(); _resizeData.Grid = grid; _resizeData.ShowsPreview = ShowsPreview; _resizeData.ResizeDirection = GetEffectiveResizeDirection(); _resizeData.ResizeBehavior = GetEffectiveResizeBehavior(_resizeData.ResizeDirection); _resizeData.SplitterLength = Math.Min(ActualWidth, ActualHeight); // Store the rows and columns to resize on drag events if (!SetupDefinitionsToResize()) { // Unable to resize, clear data _resizeData = null; return; } // Setup the preview in the adorner if ShowsPreview is true SetupPreview(); } }
private void GetDeltaConstraints(out double minDelta, out double maxDelta) { double actualLength1 = this.GetActualLength(this._resizeData.Definition1); double minSizeValue1 = ResizeData.UserMinSizeValueCache(this._resizeData.Definition1); double maxSizeValue1 = ResizeData.UserMaxSizeValueCache(this._resizeData.Definition1); double actualLength2 = this.GetActualLength(this._resizeData.Definition2); double minSizeValue2 = ResizeData.UserMinSizeValueCache(this._resizeData.Definition2); double maxSizeValue2 = ResizeData.UserMaxSizeValueCache(this._resizeData.Definition2); if (this._resizeData.SplitterIndex == this._resizeData.Definition1Index) { minSizeValue1 = Math.Max(minSizeValue1, this._resizeData.SplitterLength); } else if (this._resizeData.SplitterIndex == this._resizeData.Definition2Index) { minSizeValue2 = Math.Max(minSizeValue2, this._resizeData.SplitterLength); } if (this._resizeData.SplitBehavior == SplitBehavior.Split) { minDelta = -Math.Min((double)(actualLength1 - minSizeValue1), (double)(maxSizeValue2 - actualLength2)); maxDelta = Math.Min((double)(maxSizeValue1 - actualLength1), (double)(actualLength2 - minSizeValue2)); } else if (this._resizeData.SplitBehavior == SplitBehavior.Resize1) { minDelta = minSizeValue1 - actualLength1; maxDelta = maxSizeValue1 - actualLength1; } else { minDelta = actualLength2 - maxSizeValue2; maxDelta = actualLength2 - minSizeValue2; } }
private void InitializeData(bool ShowsPreview) { _resizeData = new ResizeData(); _resizeData.Panel = Owner; _resizeData.ShowsPreview = ShowsPreview; _resizeData.SplitterLength = Math.Min(ActualWidth, ActualHeight); _resizeData.SplitterIndex = SplitterIndex; SetupDefinitionsToResize(); SetupPreview(); }
private bool SetupDefinitionsToResize() { int num4 = (int)base.GetValue((this._resizeData.ResizeDirection == GridResizeDirection.Columns) ? Grid.ColumnSpanProperty : Grid.RowSpanProperty); if (num4 == 1) { int num2; int num3; int num = (int)base.GetValue((this._resizeData.ResizeDirection == GridResizeDirection.Columns) ? Grid.ColumnProperty : Grid.RowProperty); switch (this._resizeData.ResizeBehavior) { case GridResizeBehavior.CurrentAndNext: num2 = num; num3 = num + 1; break; case GridResizeBehavior.PreviousAndCurrent: num2 = num - 1; num3 = num; break; default: num2 = num - 1; num3 = num + 1; break; } int num5 = (this._resizeData.ResizeDirection == GridResizeDirection.Columns) ? this._resizeData.Grid.ColumnDefinitions.Count : this._resizeData.Grid.RowDefinitions.Count; if ((num2 >= 0) && (num3 < num5)) { this._resizeData.SplitterIndex = num; this._resizeData.Definition1Index = num2; this._resizeData.Definition1 = GetGridDefinition(this._resizeData.Grid, num2, this._resizeData.ResizeDirection); this._resizeData.OriginalDefinition1Length = ResizeData.UserSizeValueCache(this._resizeData.Definition1); this._resizeData.OriginalDefinition1ActualLength = this.GetActualLength(this._resizeData.Definition1); this._resizeData.Definition2Index = num3; this._resizeData.Definition2 = GetGridDefinition(this._resizeData.Grid, num3, this._resizeData.ResizeDirection); this._resizeData.OriginalDefinition2Length = ResizeData.UserSizeValueCache(this._resizeData.Definition2); this._resizeData.OriginalDefinition2ActualLength = this.GetActualLength(this._resizeData.Definition2); bool flag = IsStar(this._resizeData.Definition1); bool flag2 = IsStar(this._resizeData.Definition2); if (flag && flag2) { this._resizeData.SplitBehavior = SplitBehavior.Split; } else { this._resizeData.SplitBehavior = !flag ? SplitBehavior.Resize1 : SplitBehavior.Resize2; } return(true); } } return(false); }
/// <summary> /// Cancel the resize operation in progress /// </summary> private void CancelResize() { if (_resizeData.ShowsPreview) { RemovePreviewControl(); } else { SetLengths(_resizeData.OriginalDefinition1ActualLength, _resizeData.OriginalDefinition2ActualLength); } _resizeData = null; }
private void OnDragCompleted(DragCompletedEventArgs e) { if (this._resizeData != null) { if (this._resizeData.ShowsPreview) { this.MoveSplitter(this._resizeData.Adorner.OffsetX, this._resizeData.Adorner.OffsetY); this.RemovePreviewAdorner(); } this._resizeData = null; } }
private void CancelResize() { DependencyObject parent = base.Parent; if (this._resizeData.ShowsPreview) { this.RemovePreviewAdorner(); } else { SetDefinitionLength(this._resizeData.Definition1, this._resizeData.OriginalDefinition1Length); SetDefinitionLength(this._resizeData.Definition2, this._resizeData.OriginalDefinition2Length); } this._resizeData = null; }
/// <summary> /// Initialize the resize data and move the splitter by the specified amount /// </summary> /// <param name="horizontalChange">Horizontal amount to move the splitter</param> /// <param name="verticalChange">Vertical amount to move the splitter</param> /// <returns></returns> internal bool InitializeAndMoveSplitter(double horizontalChange, double verticalChange) { // resizing directly is not allowed if there is a mouse initiated resize operation in progress if (_resizeData != null) { return(false); } InitializeData(false); if (_resizeData == null) { return(false); } MoveSplitter(horizontalChange, verticalChange); _resizeData = null; return(true); }
internal bool KeyboardMoveSplitter(double horizontalChange, double verticalChange) { if (this._resizeData != null) { return(false); } this.InitializeData(false); if (this._resizeData == null) { return(false); } if (base.FlowDirection == FlowDirection.RightToLeft) { horizontalChange = -horizontalChange; } this.MoveSplitter(horizontalChange, verticalChange); this._resizeData = null; return(true); }
protected override void OnPointerReleased(PointerRoutedEventArgs e) { base.OnPointerReleased(e); if (_dragging) { _dragging = false; ReleasePointerCapture(e.Pointer); if (_resizeData != null) { Canvas.SetZIndex(_resizeData.ResizedTgt, 0); MoveSplitter(_resizeData.Preview.OffsetX, _resizeData.Preview.OffsetY, false); RemovePreview(); _resizeData.ClearReferences(); _resizeData = null; } ChangeVisualState(); OnLayoutChangeEnded(); } }
/// <summary> /// Handle the drag completed event to commit or cancel the resize operation in progress /// </summary> internal void DragValidator_DragCompletedEvent(object sender, DragCompletedEventArgs e) { if (_resizeData != null) { if (e.Canceled) { CancelResize(); } else { if (_resizeData.ShowsPreview) { MoveSplitter(_resizeData.PreviewControl.OffsetX, _resizeData.PreviewControl.OffsetY); RemovePreviewControl(); } } _resizeData = null; } ChangeVisualState(); }
private void InitializeData(bool ShowsPreview) { Grid parent = base.Parent as Grid; if (parent != null) { this._resizeData = new ResizeData(); this._resizeData.Grid = parent; this._resizeData.ShowsPreview = ShowsPreview; this._resizeData.ResizeDirection = this.GetEffectiveResizeDirection(); this._resizeData.SplitterLength = Math.Min(base.ActualWidth, base.ActualHeight); if (!this.SetupDefinitionsToResize()) { this._resizeData = null; } else { this.SetupPreview(); } } }
/// <summary> /// Initialize the resizeData object to hold the information for the /// resize operation in progress. /// </summary> /// <param name="showsPreview"> /// Whether or not the preview should be shown. /// </param> private void InitializeData(bool showsPreview) { Grid parent = Parent as Grid; if (parent != null) { ResizeDataInternal = new ResizeData(); ResizeDataInternal.Grid = parent; ResizeDataInternal.ShowsPreview = showsPreview; ResizeDataInternal.ResizeDirection = GetEffectiveResizeDirection(); ResizeDataInternal.ResizeBehavior = GetEffectiveResizeBehavior(ResizeDataInternal.ResizeDirection); ResizeDataInternal.SplitterLength = Math.Min(ActualWidth, ActualHeight); if (!SetupDefinitionsToResize()) { ResizeDataInternal = null; } else { SetupPreview(); } } }
private void OnDragStarted() { AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(ResizeControl); if (adornerLayer != null) { resizeData = new ResizeData { SplitterDockSide = DockCanvas.GetDock(ResizeControl), Parent = ResizeControl }; switch (resizeData.SplitterDockSide) { case Dock.Left: resizeData.MinOffset = 15.0 - ResizeControl.ContentSize; resizeData.MaxOffset = canvas.ClientBounds.Width - 32.0; break; case Dock.Top: resizeData.MinOffset = 15.0 - ResizeControl.ContentSize; resizeData.MaxOffset = canvas.ClientBounds.Height - 32.0; break; case Dock.Right: resizeData.MaxOffset = ResizeControl.ContentSize - 15.0; resizeData.MinOffset = 32.0 - canvas.ClientBounds.Width; break; case Dock.Bottom: resizeData.MaxOffset = ResizeControl.ContentSize - 15.0; resizeData.MinOffset = 32.0 - canvas.ClientBounds.Height; break; } resizeData.PreviewAdorner = new SplitPreviewAdorner(this); adornerLayer.Add(resizeData.PreviewAdorner); } }
/// <summary> /// Initialize the resizeData object to hold the information for the resize operation in progress /// </summary> /// <param name="showsPreview">Whether or not the preview should be shown</param> private void InitializeData(bool showsPreview) { Grid parent = base.Parent as Grid; if (parent != null) { _resizeData = new ResizeData(); _resizeData.Grid = parent; _resizeData.ShowsPreview = showsPreview; _resizeData.ResizeDirection = GetEffectiveResizeDirection(); _resizeData.ResizeBehavior = GetEffectiveResizeBehavior(_resizeData.ResizeDirection); _resizeData.SplitterLength = Math.Min(base.ActualWidth, base.ActualHeight); if (!SetupDefinitionsToResize()) { _resizeData = null; } else { SetupPreview(); } } }
/// <summary> /// Called by keyboard event handler to move the splitter if allowed /// </summary> /// <param name="horizontalChange">Horizontal amount to move the splitter</param> /// <param name="verticalChange">Vertical amount to move the splitter</param> /// <returns></returns> private bool KeyboardMoveSplitter(double horizontalChange, double verticalChange) { if (HasKeyboardFocus && this.IsEnabled) { // Keyboard resizing is not allowed if there is a mouse initiated resize operation in progress if (_resizeData != null) { return(false); } InitializeData(false); if (_resizeData == null) { return(false); } MoveSplitter(horizontalChange, verticalChange); _resizeData = null; return(true); } return(false); }
bool KeyboardMoveSplitter(double p_horChange, double p_verChange) { if (FlowDirection == FlowDirection.RightToLeft) { p_horChange *= -1.0; } if (HasKeyboardFocus && IsEnabled) { if (_resizeData != null) { return(false); } InitializeData(); if (_resizeData == null) { return(false); } MoveSplitter(p_horChange, p_verChange, false); _resizeData = null; return(true); } return(false); }
/// <summary> /// Cancel the resize operation in progress /// </summary> private void CancelResize() { if (_resizeData.ShowsPreview) { RemovePreviewControl(); } else { SetLengths(_resizeData.OriginalDefinition1ActualLength, _resizeData.OriginalDefinition2ActualLength); } _resizeData = null; }
/// <summary> /// Called by keyboard event handler to move the splitter if allowed /// </summary> /// <param name="horizontalChange">Horizontal amount to move the splitter</param> /// <param name="verticalChange">Vertical amount to move the splitter</param> /// <returns></returns> private bool KeyboardMoveSplitter(double horizontalChange, double verticalChange) { if (HasKeyboardFocus && this.IsEnabled) { // Keyboard resizing is not allowed if there is a mouse initiated resize operation in progress if (_resizeData != null) { return false; } InitializeData(false); if (_resizeData == null) { return false; } MoveSplitter(horizontalChange, verticalChange); _resizeData = null; return true; } return false; }
/// <summary> /// Initialize the resizeData object to hold the information for the resize operation in progress /// </summary> /// <param name="showsPreview">Whether or not the preview should be shown</param> private void InitializeData(bool showsPreview) { Grid parent = base.Parent as Grid; if (parent != null) { _resizeData = new ResizeData(); _resizeData.Grid = parent; _resizeData.ShowsPreview = showsPreview; _resizeData.ResizeDirection = GetEffectiveResizeDirection(); _resizeData.ResizeBehavior = GetEffectiveResizeBehavior(_resizeData.ResizeDirection); _resizeData.SplitterLength = Math.Min(base.ActualWidth, base.ActualHeight); if (!SetupDefinitionsToResize()) { _resizeData = null; } else { SetupPreview(); } } }
/// <summary> /// 通过事件参数设置开始移动的相关信息 /// </summary> void InitializeData() { Panel parent = Parent as Panel; if (parent == null) { return; } _resizeData = new ResizeData(); _resizeData.ResizedTgt = Owner; _resizeData.Placement = Placement ?? ItemPlacement.Left; Win win; FrameworkElement affectedTgt = null; if (Owner is Tabs tabs) { win = tabs.OwnWin; if (tabs.OwnWinItem != null) { for (int i = tabs.OwnWinItem.Items.IndexOf(tabs) - 1; i > -1; i--) { var brother = tabs.OwnWinItem.Items[i]; if (brother.Visibility == Visibility.Visible) { affectedTgt = brother; break; } } } } else if (Owner is Pane wi) { win = wi.OwnWin; if (wi.Parent is TabItemPanel pnl && pnl.Owner != null) { for (int i = pnl.Owner.Items.IndexOf(wi) - 1; i > -1; i--) { var brother = pnl.Owner.Items[i]; if (brother.Visibility == Visibility.Visible) { affectedTgt = brother; break; } } } } else { throw new Exception("GridResizer只放在Tabs或Pane中"); } var center = win.CenterItem; _resizeData.MinSize = new Size(center.MinWidth, center.MinHeight); _resizeData.MaxSize = new Size(center.ActualWidth, center.ActualHeight); if (affectedTgt != null) { _resizeData.AffectedTgt = affectedTgt; _resizeData.ResizeBehavior = ResizeBehavior.Split; } _resizeData.Init(); }
/// <summary> /// Handle the drag completed event to commit or cancel the resize operation in progress /// </summary> internal void DragValidator_DragCompletedEvent(object sender, DragCompletedEventArgs e) { if (_resizeData != null) { if (e.Canceled) { if (_resizeData.ShowsPreview) { RemovePreviewControl(); } CancelResize(); } else { if (_resizeData.ShowsPreview) { MoveSplitter(_resizeData.PreviewControl.OffsetX, _resizeData.PreviewControl.OffsetY); RemovePreviewControl(); } } _resizeData = null; } ChangeVisualState(); }
/// <summary> /// Initialize the resize data and move the splitter by the specified amount /// </summary> /// <param name="horizontalChange">Horizontal amount to move the splitter</param> /// <param name="verticalChange">Vertical amount to move the splitter</param> /// <returns></returns> internal bool InitializeAndMoveSplitter(double horizontalChange, double verticalChange) { // resizing directly is not allowed if there is a mouse initiated resize operation in progress if (_resizeData != null) { return false; } InitializeData(false); if (_resizeData == null) { return false; } MoveSplitter(horizontalChange, verticalChange); _resizeData = null; return true; }
private static bool IsStar(DefinitionBase definition) { return(ResizeData.UserSizeValueCache(definition).IsStar); }
void CancelResize() { RemovePreview(); _resizeData.CancelResize(); _resizeData = null; }
// Initialize the data needed for resizing private void InitializeData(bool ShowsPreview) { Grid grid = Parent as Grid; // If not in a grid or can't resize, do nothing if (grid != null) { // Setup data used for resizing _resizeData = new ResizeData(); _resizeData.Grid = grid; _resizeData.ShowsPreview = ShowsPreview; _resizeData.ResizeDirection = GetEffectiveResizeDirection(); _resizeData.ResizeBehavior = GetEffectiveResizeBehavior(_resizeData.ResizeDirection); _resizeData.SplitterLength = Math.Min(ActualWidth, ActualHeight); // Store the rows and columns to resize on drag events if (!SetupDefinitionsToResize()) { // Unable to resize, clear data _resizeData = null; return; } // Setup the preview in the adorner if ShowsPreview is true SetupPreview(); } }
/// <summary> /// Initialize the resizeData object to hold the information for the /// resize operation in progress. /// </summary> /// <param name="showsPreview"> /// Whether or not the preview should be shown. /// </param> private void InitializeData(bool showsPreview) { Grid parent = Parent as Grid; if (parent != null) { ResizeDataInternal = new ResizeData(); ResizeDataInternal.Grid = parent; ResizeDataInternal.ShowsPreview = showsPreview; ResizeDataInternal.ResizeDirection = GetEffectiveResizeDirection(); ResizeDataInternal.ResizeBehavior = GetEffectiveResizeBehavior(ResizeDataInternal.ResizeDirection); ResizeDataInternal.SplitterLength = Math.Min(ActualWidth, ActualHeight); if (!SetupDefinitionsToResize()) { ResizeDataInternal = null; } else { SetupPreview(); } } }