private void UserControl_MouseMove(object sender, MouseEventArgs e) { if (!dragging) { return; } GridResizeDirection effectiveResizeDirection = this.DetermineEffectiveResizeDirection(); var grid = GetGrid(); var position = e.GetPosition(grid); if (effectiveResizeDirection == GridResizeDirection.Columns) { var deltaX = position.X - this.lastPosition.X; this.ResizeColumns(grid, deltaX); } else { var deltaY = position.Y - this.lastPosition.Y; this.ResizeRows(grid, deltaY); } this.lastPosition = position; }
/// <summary> /// Determine the resize behavior based on the given direction and /// alignment. /// </summary> /// <param name="direction">Inherited code: Requires comment.</param> /// <returns>Inherited code: Requires comment 1.</returns> private GridResizeBehavior GetEffectiveResizeBehavior(GridResizeDirection direction) { if (direction != GridResizeDirection.Columns) { switch (VerticalAlignment) { case VerticalAlignment.Top: return(GridResizeBehavior.PreviousAndCurrent); case VerticalAlignment.Bottom: return(GridResizeBehavior.CurrentAndNext); } return(GridResizeBehavior.PreviousAndNext); } else { switch (HorizontalAlignment) { case HorizontalAlignment.Left: return(GridResizeBehavior.PreviousAndCurrent); case HorizontalAlignment.Right: return(GridResizeBehavior.CurrentAndNext); } return(GridResizeBehavior.PreviousAndNext); } }
/// <summary> /// This code will run whenever the effective resize direction changes, /// to update the template being used to display this control. /// </summary> private void UpdateTemplateOrientation() { GridResizeDirection newGridResizeDirection = GetEffectiveResizeDirection(); if (_currentGridResizeDirection != newGridResizeDirection) { if (newGridResizeDirection == GridResizeDirection.Columns) { if (ElementHorizontalTemplateFrameworkElement != null) { ElementHorizontalTemplateFrameworkElement.Visibility = Visibility.Collapsed; } if (ElementVerticalTemplateFrameworkElement != null) { ElementVerticalTemplateFrameworkElement.Visibility = Visibility.Visible; } } else { if (ElementHorizontalTemplateFrameworkElement != null) { ElementHorizontalTemplateFrameworkElement.Visibility = Visibility.Visible; } if (ElementVerticalTemplateFrameworkElement != null) { ElementVerticalTemplateFrameworkElement.Visibility = Visibility.Collapsed; } } _currentGridResizeDirection = newGridResizeDirection; } }
// Checks the control alignment and Width/Height to detect the control resize direction columns/rows private GridResizeDirection GetResizeDirection() { GridResizeDirection direction = ResizeDirection; if (direction == GridResizeDirection.Auto) { // When HorizontalAlignment is Left, Right or Center, resize Columns if (HorizontalAlignment != HorizontalAlignment.Stretch) { direction = GridResizeDirection.Columns; } // When VerticalAlignment is Top, Bottom or Center, resize Rows else if (VerticalAlignment != VerticalAlignment.Stretch) { direction = GridResizeDirection.Rows; } // Check Width vs Height else if (ActualWidth <= ActualHeight) { direction = GridResizeDirection.Columns; } else { direction = GridResizeDirection.Rows; } } return(direction); }
/// <summary> /// Called before the PointerPressed event occurs. /// </summary> /// <param name="e">Event data for the event.</param> protected override void OnPointerPressed(Windows.UI.Xaml.Input.PointerRoutedEventArgs e) { if (_dragPointer != null) { return; } _dragPointer = e.Pointer.PointerId; _effectiveResizeDirection = this.DetermineEffectiveResizeDirection(); _parentGrid = GetGrid(); _previewDraggingStartPosition = e.GetCurrentPoint(_parentGrid).Position; _lastPosition = _previewDraggingStartPosition; _isDragging = true; if (ShowsPreview) { //this.Dispatcher.Invoke( // CoreDispatcherPriority.High, // (s, e2) => StartPreviewDragging(e), // this, // null); StartPreviewDragging(e); } else { StartDirectDragging(e); } }
// Converts BasedOnAlignment direction to Rows, Columns, or Both depending on its width/height private GridResizeDirection GetEffectiveResizeDirection() { GridResizeDirection direction = ResizeDirection; if (direction == GridResizeDirection.Auto) { // When HorizontalAlignment is Left, Right or Center, resize Columns if (HorizontalAlignment != HorizontalAlignment.Stretch) { direction = GridResizeDirection.Columns; } else if (VerticalAlignment != VerticalAlignment.Stretch) { direction = GridResizeDirection.Rows; } else if (ActualWidth <= ActualHeight)// Fall back to Width vs Height { direction = GridResizeDirection.Columns; } else { direction = GridResizeDirection.Rows; } } return(direction); }
private void GridSplitter_Loaded(object sender, RoutedEventArgs e) { _resizeDirection = GetResizeDirection(); _resizeBehavior = GetResizeBehavior(); // Adding Grip to Grid Splitter if (Element == default(UIElement)) { CreateGripperDisplay(); Element = _gripperDisplay; } if (_hoverWrapper == null) { var hoverWrapper = new GripperHoverWrapper( CursorBehavior == SplitterCursorBehavior.ChangeOnSplitterHover ? this : Element, _resizeDirection, GripperCursor, GripperCustomCursorResource); ManipulationStarted += hoverWrapper.SplitterManipulationStarted; ManipulationCompleted += hoverWrapper.SplitterManipulationCompleted; _hoverWrapper = hoverWrapper; } }
// Token: 0x06004DC9 RID: 19913 RVA: 0x0015EC88 File Offset: 0x0015CE88 private GridResizeDirection GetEffectiveResizeDirection() { GridResizeDirection gridResizeDirection = this.ResizeDirection; if (gridResizeDirection == GridResizeDirection.Auto) { if (base.HorizontalAlignment != HorizontalAlignment.Stretch) { gridResizeDirection = GridResizeDirection.Columns; } else if (base.VerticalAlignment != VerticalAlignment.Stretch) { gridResizeDirection = GridResizeDirection.Rows; } else if (base.ActualWidth <= base.ActualHeight) { gridResizeDirection = GridResizeDirection.Columns; } else { gridResizeDirection = GridResizeDirection.Rows; } } return(gridResizeDirection); }
public GridSplitter() { Focusable = true; DragDelta += delegate(object sender, global::System.Windows.Controls.Primitives.DragDeltaEventArgs e) { Grid grid = Parent as Grid; if (grid == null) { return; } GridResizeDirection resize_direction = GetActualResizeDirection(); double drag_increment = DragIncrement; if (drag_increment == 1) { HandleChange(grid, resize_direction, resize_direction == GridResizeDirection.Rows ? e.VerticalChange : e.HorizontalChange); } else { Point mouse_position = Mouse.GetPosition(this); double increments = Math.Round((resize_direction == GridResizeDirection.Rows ? mouse_position.Y : mouse_position.X) / drag_increment); if (increments != 0) { HandleChange(grid, resize_direction, increments * drag_increment); } } }; }
protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); GridResizeDirection effectiveResizeDirection = this.DetermineEffectiveResizeDirection(); if (effectiveResizeDirection == GridResizeDirection.Columns) { if (e.Key == Key.Left) { this.ResizeColumns(this.GetGrid(), -KeyboardIncrement); e.Handled = true; } else if (e.Key == Key.Right) { this.ResizeColumns(this.GetGrid(), KeyboardIncrement); e.Handled = true; } } else { if (e.Key == Key.Up) { this.ResizeRows(this.GetGrid(), -KeyboardIncrement); e.Handled = true; } else if (e.Key == Key.Down) { this.ResizeRows(this.GetGrid(), KeyboardIncrement); e.Handled = true; } } }
/// <summary> /// Create a DefinitionAbstraction instance for the given row or column /// index in the grid. /// </summary> /// <param name="grid">Inherited code: Requires comment.</param> /// <param name="index">Inherited code: Requires comment 1.</param> /// <param name="direction">Inherited code: Requires comment 2.</param> /// <returns>Inherited code: Requires comment 3.</returns> private static DefinitionAbstraction GetGridDefinition(Grid grid, int index, GridResizeDirection direction) { if (direction != GridResizeDirection.Columns) { return(new DefinitionAbstraction(grid.RowDefinitions[index])); } return(new DefinitionAbstraction(grid.ColumnDefinitions[index])); }
private static bool IsValidResizeDirection(object o) { GridResizeDirection resizeDirection = (GridResizeDirection)o; return(resizeDirection == GridResizeDirection.Auto || resizeDirection == GridResizeDirection.Columns || resizeDirection == GridResizeDirection.Rows); }
private static void OnResizeDirectionChanged(GridSplitter gridSplitter, GridResizeDirection oldValue, GridResizeDirection newValue) { ResettableGridSplitterBehavior behavior; if (behaviors.TryGetValue(gridSplitter, out behavior)) { behavior.OnResizeDirectionChanged(oldValue, newValue); } }
/// <summary> /// Handles changes to the ResizeDirection property. /// </summary> /// <param name="d"> /// The <see cref="DependencyObject"/> on which /// the property has changed value. /// </param> /// <param name="e"> /// Event data that is issued by any event that /// tracks changes to the effective value of this property. /// </param> private static void OnResizeDirectionChanged( DependencyObject d, DependencyPropertyChangedEventArgs e) { var target = (SimpleGridSplitter)d; GridResizeDirection oldResizeDirection = (GridResizeDirection)e.OldValue; GridResizeDirection newResizeDirection = target.ResizeDirection; target.OnResizeDirectionChanged(oldResizeDirection, newResizeDirection); }
private static bool IsValidResizeDirection(object o) { GridResizeDirection direction = (GridResizeDirection)o; if ((direction != GridResizeDirection.Auto) && (direction != GridResizeDirection.Columns)) { return(direction == GridResizeDirection.Rows); } return(true); }
// Determines the indices for accessign ColumnDefinitions or RowDefinitions based on resize direction and behavior private Tuple <int?, int?> GetDefinitionIndices() { GridResizeDirection effectiveResizeDirection = this.GetEffectiveResizeDirection(); GridResizeBehavior effectiveResizeBehavior = this.GetEffectiveResizeBehavior(effectiveResizeDirection); int currentIndex; int count; switch (effectiveResizeDirection) { case GridResizeDirection.Columns: currentIndex = (int)this.gridSplitter.GetValue(Grid.ColumnProperty); count = this.grid.ColumnDefinitions.Count; break; case GridResizeDirection.Rows: currentIndex = (int)this.gridSplitter.GetValue(Grid.RowProperty); count = this.grid.RowDefinitions.Count; break; default: return(new Tuple <int?, int?>(null, null)); } int?length1Index = currentIndex; int?length2Index = currentIndex; switch (effectiveResizeBehavior) { case GridResizeBehavior.CurrentAndNext: length2Index++; break; case GridResizeBehavior.PreviousAndCurrent: length1Index--; break; case GridResizeBehavior.PreviousAndNext: length2Index++; length1Index--; break; } if (length1Index < 0 || length1Index >= count) { length1Index = null; } if (length2Index < 0 || length2Index >= count) { length2Index = null; } return(new Tuple <int?, int?>(length1Index, length2Index)); }
/// <summary> /// Called when template should be applied to the control /// </summary> public override void OnApplyTemplate() { base.OnApplyTemplate(); _elementHorizontalTemplateFrameworkElement = this.GetTemplateChild(GridSplitter.ElementHorizontalTemplateName) as FrameworkElement; _elementVerticalTemplateFrameworkElement = this.GetTemplateChild(GridSplitter.ElementVerticalTemplateName) as FrameworkElement; // We need to recalculate the orientation, so set _currentGridResizeDirection back to Auto _currentGridResizeDirection = GridResizeDirection.Auto; UpdateTemplateOrientation(); ChangeVisualState(false); }
// Checks the control alignment and Width/Height to detect the control resize direction columns/rows private GridResizeDirection GetResizeDirection() { GridResizeDirection direction = ResizeDirection; if (direction == GridResizeDirection.Auto) { // Check Width vs Height. If width and height cannot be determined, check if there is one of the sizes that is set explicitely, or check the horizontal and vertical alignments: Size actualSize = this.INTERNAL_GetActualWidthAndHeight(); if (!double.IsNaN(actualSize.Width) && !double.IsNaN(actualSize.Height) && actualSize.Width > 0 && actualSize.Height > 0) { if (actualSize.Width <= actualSize.Height) { direction = GridResizeDirection.Columns; } else { direction = GridResizeDirection.Rows; } } else { // When Width is set but not Height, resize Columns: if (!double.IsNaN(actualSize.Width) && actualSize.Width > 0) { direction = GridResizeDirection.Columns; } // When Height is set but not Width, resize Rows: else if (!double.IsNaN(actualSize.Height) && actualSize.Height > 0) { direction = GridResizeDirection.Rows; } // When HorizontalAlignment is Left, Right or Center, resize Columns: else if (HorizontalAlignment != HorizontalAlignment.Stretch) { direction = GridResizeDirection.Columns; } // When VerticalAlignment is Top, Bottom or Center, resize Rows: else if (VerticalAlignment != VerticalAlignment.Stretch) { direction = GridResizeDirection.Rows; } } } return(direction); }
// Token: 0x06004DCA RID: 19914 RVA: 0x0015ECD0 File Offset: 0x0015CED0 private GridResizeBehavior GetEffectiveResizeBehavior(GridResizeDirection direction) { GridResizeBehavior gridResizeBehavior = this.ResizeBehavior; if (gridResizeBehavior == GridResizeBehavior.BasedOnAlignment) { if (direction == GridResizeDirection.Columns) { HorizontalAlignment horizontalAlignment = base.HorizontalAlignment; if (horizontalAlignment != HorizontalAlignment.Left) { if (horizontalAlignment != HorizontalAlignment.Right) { gridResizeBehavior = GridResizeBehavior.PreviousAndNext; } else { gridResizeBehavior = GridResizeBehavior.CurrentAndNext; } } else { gridResizeBehavior = GridResizeBehavior.PreviousAndCurrent; } } else { VerticalAlignment verticalAlignment = base.VerticalAlignment; if (verticalAlignment != VerticalAlignment.Top) { if (verticalAlignment != VerticalAlignment.Bottom) { gridResizeBehavior = GridResizeBehavior.PreviousAndNext; } else { gridResizeBehavior = GridResizeBehavior.CurrentAndNext; } } else { gridResizeBehavior = GridResizeBehavior.PreviousAndCurrent; } } } return(gridResizeBehavior); }
/// <inheritdoc /> protected override void OnManipulationStarted(ManipulationStartedRoutedEventArgs e) { // saving the previous state PreviousCursor = Window.Current.CoreWindow.PointerCursor; _resizeDirection = GetResizeDirection(); _resizeBehavior = GetResizeBehavior(); if (_resizeDirection == GridResizeDirection.Columns) { Window.Current.CoreWindow.PointerCursor = ColumnsSplitterCursor; } else if (_resizeDirection == GridResizeDirection.Rows) { Window.Current.CoreWindow.PointerCursor = RowSplitterCursor; } base.OnManipulationStarted(e); }
private GridResizeDirection GetEffectiveResizeDirection() { GridResizeDirection resizeDirection = this.ResizeDirection; if (resizeDirection != GridResizeDirection.Auto) { return(resizeDirection); } if (base.HorizontalAlignment != HorizontalAlignment.Stretch) { return(GridResizeDirection.Columns); } if ((base.VerticalAlignment == VerticalAlignment.Stretch) && (base.ActualWidth <= base.ActualHeight)) { return(GridResizeDirection.Columns); } return(GridResizeDirection.Rows); }
protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); Grid grid = Parent as Grid; if (grid == null) { return; } double keyboard_increment_multiplier = 0; GridResizeDirection resize_direction = GetActualResizeDirection(); if (resize_direction == GridResizeDirection.Rows) { switch (e.Key) { case Key.Up: keyboard_increment_multiplier = -1; break; case Key.Down: keyboard_increment_multiplier = 1; break; } } else { switch (e.Key) { case Key.Left: keyboard_increment_multiplier = -1; break; case Key.Right: keyboard_increment_multiplier = 1; break; } } if (keyboard_increment_multiplier != 0) { HandleChange(grid, resize_direction, KeyboardIncrement * keyboard_increment_multiplier); e.Handled = true; } }
// Convert BasedOnAlignment to Next/Prev/Both depending on alignment and Direction private GridResizeBehavior GetEffectiveResizeBehavior(GridResizeDirection direction) { GridResizeBehavior resizeBehavior = ResizeBehavior; if (resizeBehavior == GridResizeBehavior.BasedOnAlignment) { if (direction == GridResizeDirection.Columns) { switch (HorizontalAlignment) { case HorizontalAlignment.Left: resizeBehavior = GridResizeBehavior.PreviousAndCurrent; break; case HorizontalAlignment.Right: resizeBehavior = GridResizeBehavior.CurrentAndNext; break; default: resizeBehavior = GridResizeBehavior.PreviousAndNext; break; } } else { switch (VerticalAlignment) { case VerticalAlignment.Top: resizeBehavior = GridResizeBehavior.PreviousAndCurrent; break; case VerticalAlignment.Bottom: resizeBehavior = GridResizeBehavior.CurrentAndNext; break; default: resizeBehavior = GridResizeBehavior.PreviousAndNext; break; } } } return(resizeBehavior); }
private void RestoreSplitterPosition() { if (DesignerProperties.GetIsInDesignMode(this.gridSplitter)) { return; } GridResizeDirection effectiveResizeDirection = GetEffectiveResizeDirection(); switch (effectiveResizeDirection) { case GridResizeDirection.Columns: this.RestoreColumnWidths(); break; case GridResizeDirection.Rows: this.RestoreRowHeights(); break; } }
// Token: 0x06004DB8 RID: 19896 RVA: 0x0015EAE8 File Offset: 0x0015CCE8 private static object CoerceCursor(DependencyObject o, object value) { GridSplitter gridSplitter = (GridSplitter)o; bool flag; BaseValueSourceInternal valueSource = gridSplitter.GetValueSource(FrameworkElement.CursorProperty, null, out flag); if (value == null && valueSource == BaseValueSourceInternal.Default) { GridResizeDirection effectiveResizeDirection = gridSplitter.GetEffectiveResizeDirection(); if (effectiveResizeDirection == GridResizeDirection.Columns) { return(Cursors.SizeWE); } if (effectiveResizeDirection == GridResizeDirection.Rows) { return(Cursors.SizeNS); } } return(value); }
GridResizeBehavior GetActualResizeBehavior(GridResizeDirection resizeDirection) { GridResizeBehavior value = ResizeBehavior; if (value == GridResizeBehavior.BasedOnAlignment) { if (resizeDirection == GridResizeDirection.Rows) { switch (VerticalAlignment) { case VerticalAlignment.Top: return(GridResizeBehavior.PreviousAndCurrent); case VerticalAlignment.Bottom: return(GridResizeBehavior.CurrentAndNext); default: return(GridResizeBehavior.PreviousAndNext); } } else { switch (HorizontalAlignment) { case HorizontalAlignment.Left: return(GridResizeBehavior.PreviousAndCurrent); case HorizontalAlignment.Right: return(GridResizeBehavior.CurrentAndNext); default: return(GridResizeBehavior.PreviousAndNext); } } } else { return(value); } }
internal static void SetResizeDirection(GridSplitter gridSplitter, GridResizeDirection resizeDirection) { switch (resizeDirection) { case GridResizeDirection.Columns: gridSplitter.VerticalAlignment = VerticalAlignment.Stretch; gridSplitter.HorizontalAlignment = HorizontalAlignment.Center; break; case GridResizeDirection.Rows: gridSplitter.VerticalAlignment = VerticalAlignment.Center; gridSplitter.HorizontalAlignment = HorizontalAlignment.Stretch; break; } #if !SILVERLIGHT gridSplitter.ResizeDirection = resizeDirection; #endif }
private void OnDragDelta(DragDeltaEventArgs e) { if (!dragging) { return; } GridResizeDirection effectiveResizeDirection = this.DetermineEffectiveResizeDirection(); var grid = GetGrid(); if (effectiveResizeDirection == GridResizeDirection.Columns) { var deltaX = e.HorizontalChange; this.ResizeColumns(grid, deltaX); } else { var deltaY = e.VerticalChange; this.ResizeRows(grid, deltaY); } }
private GridResizeBehavior GetEffectiveResizeBehavior(GridResizeDirection direction) { GridResizeBehavior resizeBehavior = this.ResizeBehavior; if (resizeBehavior != GridResizeBehavior.BasedOnAlignment) { return(resizeBehavior); } if (direction != GridResizeDirection.Columns) { switch (base.VerticalAlignment) { case VerticalAlignment.Top: return(GridResizeBehavior.PreviousAndCurrent); case VerticalAlignment.Center: goto Label_0058; case VerticalAlignment.Bottom: return(GridResizeBehavior.CurrentAndNext); } } else { switch (base.HorizontalAlignment) { case HorizontalAlignment.Left: return(GridResizeBehavior.PreviousAndCurrent); case HorizontalAlignment.Right: return(GridResizeBehavior.CurrentAndNext); } return(GridResizeBehavior.PreviousAndNext); } Label_0058: return(GridResizeBehavior.PreviousAndNext); }
GridResizeDirection GetActualResizeDirection() { GridResizeDirection value = ResizeDirection; if (value == GridResizeDirection.Auto) { if (HorizontalAlignment != HorizontalAlignment.Stretch) { return(GridResizeDirection.Columns); } else if (VerticalAlignment != VerticalAlignment.Stretch) { return(GridResizeDirection.Rows); } else { return(ActualHeight >= ActualWidth ? GridResizeDirection.Columns : GridResizeDirection.Rows); } } else { return(value); } }
// Convert BasedOnAlignment to Next/Prev/Both depending on alignment and Direction private GridResizeBehavior GetEffectiveResizeBehavior(GridResizeDirection direction) { GridResizeBehavior resizeBehavior = ResizeBehavior; if (resizeBehavior == GridResizeBehavior.BasedOnAlignment) { if (direction == GridResizeDirection.Columns) { switch (HorizontalAlignment) { case HorizontalAlignment.Left: resizeBehavior = GridResizeBehavior.PreviousAndCurrent; break; case HorizontalAlignment.Right: resizeBehavior = GridResizeBehavior.CurrentAndNext; break; default: resizeBehavior = GridResizeBehavior.PreviousAndNext; break; } } else { switch (VerticalAlignment) { case VerticalAlignment.Top: resizeBehavior = GridResizeBehavior.PreviousAndCurrent; break; case VerticalAlignment.Bottom: resizeBehavior = GridResizeBehavior.CurrentAndNext; break; default: resizeBehavior = GridResizeBehavior.PreviousAndNext; break; } } } return resizeBehavior; }
// Gets Column or Row definition at index from grid based on resize direction private static DefinitionBase GetGridDefinition(Grid grid, int index, GridResizeDirection direction) { return direction == GridResizeDirection.Columns ? (DefinitionBase)grid.ColumnDefinitions[index] : (DefinitionBase)grid.RowDefinitions[index]; }
GridResizeBehavior GetActualResizeBehavior (GridResizeDirection resizeDirection) { GridResizeBehavior value = ResizeBehavior; if (value == GridResizeBehavior.BasedOnAlignment) if (resizeDirection == GridResizeDirection.Rows) switch (VerticalAlignment) { case VerticalAlignment.Top: return GridResizeBehavior.PreviousAndCurrent; case VerticalAlignment.Bottom: return GridResizeBehavior.CurrentAndNext; default: return GridResizeBehavior.PreviousAndNext; } else switch (HorizontalAlignment) { case HorizontalAlignment.Left: return GridResizeBehavior.PreviousAndCurrent; case HorizontalAlignment.Right: return GridResizeBehavior.CurrentAndNext; default: return GridResizeBehavior.PreviousAndNext; } else return value; }
void HandleChange (Grid grid, GridResizeDirection resizeDirection, double change) { GridResizeBehavior resize_behavior = GetActualResizeBehavior (resizeDirection); int position_in_grid; int definition_index1; int definition_index2; double definition1_actual_size; double definition2_actual_size; double minimum_size1; double minimum_size2; if (resizeDirection == GridResizeDirection.Rows) { position_in_grid = Grid.GetRow (this); switch (resize_behavior) { case GridResizeBehavior.CurrentAndNext: definition_index1 = position_in_grid; definition_index2 = position_in_grid + 1; break; case GridResizeBehavior.PreviousAndCurrent: definition_index1 = position_in_grid - 1; definition_index2 = position_in_grid; break; default: definition_index1 = position_in_grid - 1; definition_index2 = position_in_grid + 1; break; } if (CheckDefinitionIndex (grid.RowDefinitions, definition_index1)) return; if (CheckDefinitionIndex (grid.RowDefinitions, definition_index2)) return; RowDefinition definition1 = grid.RowDefinitions [definition_index1]; RowDefinition definition2 = grid.RowDefinitions [definition_index2]; switch (resize_behavior) { case GridResizeBehavior.PreviousAndNext: minimum_size1 = 0; minimum_size2 = 0; break; default: switch (VerticalAlignment) { case VerticalAlignment.Top: minimum_size1 = 0; minimum_size2 = ActualHeight; break; case VerticalAlignment.Bottom: minimum_size1 = ActualHeight; minimum_size2 = 0; break; default: minimum_size1 = ActualHeight; minimum_size2 = 0; break; } break; } definition1_actual_size = definition1.ActualHeight; if (definition1_actual_size + change < minimum_size1) change = minimum_size1 - definition1_actual_size; definition2_actual_size = definition2.ActualHeight; if (definition2_actual_size - change < minimum_size2) change = definition2_actual_size - minimum_size2; definition1.Height = new GridLength (definition1_actual_size + change); definition2.Height = new GridLength (definition2_actual_size - change); } else { position_in_grid = Grid.GetColumn (this); switch (resize_behavior) { case GridResizeBehavior.CurrentAndNext: definition_index1 = position_in_grid; definition_index2 = position_in_grid + 1; break; case GridResizeBehavior.PreviousAndCurrent: definition_index1 = position_in_grid - 1; definition_index2 = position_in_grid; break; default: definition_index1 = position_in_grid - 1; definition_index2 = position_in_grid + 1; break; } if (CheckDefinitionIndex (grid.RowDefinitions, definition_index1)) return; if (CheckDefinitionIndex (grid.RowDefinitions, definition_index2)) return; ColumnDefinition definition1 = grid.ColumnDefinitions [definition_index1]; ColumnDefinition definition2 = grid.ColumnDefinitions [definition_index2]; switch (resize_behavior) { case GridResizeBehavior.PreviousAndNext: minimum_size1 = 0; minimum_size2 = 0; break; default: switch (HorizontalAlignment) { case HorizontalAlignment.Left: minimum_size1 = 0; minimum_size2 = ActualWidth; break; case HorizontalAlignment.Right: minimum_size1 = ActualWidth; minimum_size2 = 0; break; default: minimum_size1 = ActualWidth; minimum_size2 = 0; break; } break; } definition1_actual_size = definition1.ActualWidth; if (definition1_actual_size + change < minimum_size1) change = minimum_size1 - definition1_actual_size; definition2_actual_size = definition2.ActualWidth; if (definition2_actual_size - change < minimum_size2) change = definition2_actual_size - minimum_size2; definition1.Width = new GridLength (definition1_actual_size + change); definition2.Width = new GridLength (definition2_actual_size - change); } }
protected override void OnPointerPressed(Windows.UI.Xaml.Input.PointerRoutedEventArgs e) { if (this.dragPointer != null) return; this.dragPointer = e.Pointer.PointerId; this.effectiveResizeDirection = this.DetermineEffectiveResizeDirection(); this.parentGrid = GetGrid(); this.previewDraggingStartPosition = e.GetCurrentPoint(this.parentGrid).Position; this.lastPosition = this.previewDraggingStartPosition; this.isDragging = true; if (ShowsPreview) { //this.Dispatcher.Invoke( // CoreDispatcherPriority.High, // (s, e2) => StartPreviewDragging(e), // this, // null); StartPreviewDragging(e); } else StartDirectDragging(e); }
/// <summary> /// Determine the resize behavior based on the given direction and alignment /// </summary> private GridResizeBehavior GetEffectiveResizeBehavior(GridResizeDirection direction) { if (direction != GridResizeDirection.Columns) { switch (base.VerticalAlignment) { case VerticalAlignment.Top: return GridResizeBehavior.PreviousAndCurrent; case VerticalAlignment.Bottom: return GridResizeBehavior.CurrentAndNext; } return GridResizeBehavior.PreviousAndNext; } else { switch (base.HorizontalAlignment) { case HorizontalAlignment.Left: return GridResizeBehavior.PreviousAndCurrent; case HorizontalAlignment.Right: return GridResizeBehavior.CurrentAndNext; } return GridResizeBehavior.PreviousAndNext; } }
/// <summary> /// Create a DefinitionAbstraction instance for the given row or column index in the grid /// </summary> private static DefinitionAbstraction GetGridDefinition(Grid grid, int index, GridResizeDirection direction) { if (direction != GridResizeDirection.Columns) { return new DefinitionAbstraction(grid.RowDefinitions[index]); } return new DefinitionAbstraction(grid.ColumnDefinitions[index]); }
/// <summary> /// Provides derived classes an opportunity to handle changes /// to the ResizeDirection property. /// </summary> /// <param name="oldResizeDirection">The old ResizeDirection value</param> /// <param name="newResizeDirection">The new ResizeDirection value</param> protected virtual void OnResizeDirectionChanged( GridResizeDirection oldResizeDirection, GridResizeDirection newResizeDirection) { this.DetermineResizeCursor(); this.UpdateVisualState(); }
/// <summary> /// Builds the visual tree for the /// <see cref="T:Microsoft.Silverlight.Testing.Controls.GridSplitter" /> /// control when a new template is applied. /// </summary> public override void OnApplyTemplate() { base.OnApplyTemplate(); ElementHorizontalTemplateFrameworkElement = this.GetTemplateChild(GridSplitter.ElementHorizontalTemplateName) as FrameworkElement; ElementVerticalTemplateFrameworkElement = this.GetTemplateChild(GridSplitter.ElementVerticalTemplateName) as FrameworkElement; // We need to recalculate the orientation, so set // _currentGridResizeDirection back to Auto _currentGridResizeDirection = GridResizeDirection.Auto; UpdateTemplateOrientation(); ChangeVisualState(false); }
private void StartPreviewDragging(Windows.UI.Xaml.Input.PointerRoutedEventArgs e) { this.isDraggingPreview = true; this.previewPopup = new Popup { Width = this.parentGrid.ActualWidth, Height = this.parentGrid.ActualHeight }; this.previewPopup.IsOpen = true; this.previewPopupHostGrid = new Grid { VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Stretch, HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Stretch }; this.parentGrid.Children.Add(this.previewPopupHostGrid); if (this.parentGrid.RowDefinitions.Count > 0) Grid.SetRowSpan(this.previewPopupHostGrid, this.parentGrid.RowDefinitions.Count); if (this.parentGrid.ColumnDefinitions.Count > 0) Grid.SetColumnSpan(this.previewPopupHostGrid, this.parentGrid.ColumnDefinitions.Count); this.previewPopupHostGrid.Children.Add(this.previewPopup); this.previewGrid = new Grid { Width = this.parentGrid.ActualWidth, Height = this.parentGrid.ActualHeight }; this.previewPopup.Child = this.previewGrid; foreach (var definition in this.parentGrid.RowDefinitions) { var definitionCopy = new RowDefinition { Height = definition.Height, MaxHeight = definition.MaxHeight, MinHeight = definition.MinHeight }; this.previewGrid.RowDefinitions.Add(definitionCopy); } foreach (var definition in this.parentGrid.ColumnDefinitions) { var w = definition.Width; var mxw = definition.MaxWidth; var mnw = definition.MinWidth; var definitionCopy = new ColumnDefinition(); definitionCopy.Width = w; definition.MinWidth = mnw; if (!double.IsInfinity(definition.MaxWidth)) { definition.MaxWidth = mxw; } //{ // Width = definition.Width, // MaxWidth = definition.MaxWidth, // MinWidth = definition.MinWidth //}; this.previewGrid.ColumnDefinitions.Add(definitionCopy); } this.previewGridSplitter = new CustomGridSplitter { Opacity = 0.0, ShowsPreview = false, Width = this.Width, Height = this.Height, Margin = this.Margin, VerticalAlignment = this.VerticalAlignment, HorizontalAlignment = this.HorizontalAlignment, ResizeBehavior = this.ResizeBehavior, ResizeDirection = this.ResizeDirection, KeyboardIncrement = this.KeyboardIncrement }; Grid.SetColumn(this.previewGridSplitter, Grid.GetColumn(this)); var cs = Grid.GetColumnSpan(this); if (cs > 0) Grid.SetColumnSpan(this.previewGridSplitter, cs); Grid.SetRow(this.previewGridSplitter, Grid.GetRow(this)); var rs = Grid.GetRowSpan(this); if (rs > 0) Grid.SetRowSpan(this.previewGridSplitter, rs); this.previewGrid.Children.Add(this.previewGridSplitter); this.previewControlBorder = new Border { Width = this.Width, Height = this.Height, Margin = this.Margin, VerticalAlignment = this.VerticalAlignment, HorizontalAlignment = this.HorizontalAlignment, }; Grid.SetColumn(this.previewControlBorder, Grid.GetColumn(this)); if (cs > 0) Grid.SetColumnSpan(this.previewControlBorder, cs); Grid.SetRow(this.previewControlBorder, Grid.GetRow(this)); if (rs > 0) Grid.SetRowSpan(this.previewControlBorder, rs); this.previewGrid.Children.Add(this.previewControlBorder); this.previewControl = new GridSplitterPreviewControl(); if (this.PreviewStyle != null) this.previewControl.Style = this.PreviewStyle; this.previewControlBorder.Child = this.previewControl; this.previewPopup.Child = this.previewGrid; //await this.previewGridSplitter.WaitForLoadedAsync(); //this.previewGridSplitter.OnPointerPressed(e); this.previewGridSplitter.dragPointer = e.Pointer.PointerId; this.previewGridSplitter.effectiveResizeDirection = this.DetermineEffectiveResizeDirection(); this.previewGridSplitter.parentGrid = this.previewGrid; this.previewGridSplitter.lastPosition = e.GetCurrentPoint(this.previewGrid).Position; this.previewGridSplitter.isDragging = true; this.previewGridSplitter.StartDirectDragging(e); this.previewGridSplitter.DraggingCompleted += previewGridSplitter_DraggingCompleted; }