/// <summary> /// Set the lengths of the two definitions depending on the split /// behavior. /// </summary> /// <param name="definition1Pixels"> /// Inherited code: Requires comment. /// </param> /// <param name="definition2Pixels"> /// Inherited code: Requires comment 1. /// </param> private void SetLengths(double definition1Pixels, double definition2Pixels) { if (ResizeDataInternal.SplitBehavior == SplitBehavior.Split) { IEnumerable enumerable = (ResizeDataInternal.ResizeDirection == GridResizeDirection.Columns) ? ((IEnumerable)ResizeDataInternal.Grid.ColumnDefinitions) : ((IEnumerable)ResizeDataInternal.Grid.RowDefinitions); int definitionIndex = 0; DefinitionAbstraction definitionAbstraction; foreach (DependencyObject definition in enumerable) { definitionAbstraction = new DefinitionAbstraction(definition); if (definitionIndex == ResizeDataInternal.Definition1Index) { SetDefinitionLength(definitionAbstraction, new GridLength(definition1Pixels, GridUnitType.Star)); } else if (definitionIndex == ResizeDataInternal.Definition2Index) { SetDefinitionLength(definitionAbstraction, new GridLength(definition2Pixels, GridUnitType.Star)); } else if (IsStar(definitionAbstraction)) { SetDefinitionLength(definitionAbstraction, new GridLength(GetActualLength(definitionAbstraction), GridUnitType.Star)); } definitionIndex++; } } else if (ResizeDataInternal.SplitBehavior == SplitBehavior.ResizeDefinition1) { SetDefinitionLength(ResizeDataInternal.Definition1, new GridLength(definition1Pixels)); } else { SetDefinitionLength(ResizeDataInternal.Definition2, new GridLength(definition2Pixels)); } }
/// <summary> /// Move the splitter and resize the affected columns or rows. /// </summary> /// <param name="horizontalChange"> /// Amount to resize horizontally. /// </param> /// <param name="verticalChange"> /// Amount to resize vertically. /// </param> /// <remarks> /// Only one of horizontalChange or verticalChange will be non-zero. /// </remarks> private void MoveSplitter(double horizontalChange, double verticalChange) { double resizeChange = (ResizeDataInternal.ResizeDirection == GridResizeDirection.Columns) ? horizontalChange : verticalChange; DefinitionAbstraction definition1 = ResizeDataInternal.Definition1; DefinitionAbstraction definition2 = ResizeDataInternal.Definition2; if ((definition1 != null) && (definition2 != null)) { double definition1ActualLength = GetActualLength(definition1); double definition2ActualLength = GetActualLength(definition2); if ((ResizeDataInternal.SplitBehavior == SplitBehavior.Split) && !DoubleUtil.AreClose((double)(definition1ActualLength + definition2ActualLength), (double)(ResizeDataInternal.OriginalDefinition1ActualLength + ResizeDataInternal.OriginalDefinition2ActualLength))) { this.CancelResize(); } else { double[] changeRange = GetDeltaConstraints(); Debug.Assert(changeRange.Length == 2, "The changeRange should contain two elements!"); double minDelta = changeRange[0]; double maxDelta = changeRange[1]; resizeChange = Math.Min(Math.Max(resizeChange, minDelta), maxDelta); double newDefinition1Length = definition1ActualLength + resizeChange; double newDefinition2Length = definition2ActualLength - resizeChange; SetLengths(newDefinition1Length, newDefinition2Length); } } }
/// <summary> /// Determine if the given definition has its size set to the "*" value. /// </summary> /// <param name="definition">Inherited code: Requires comment.</param> /// <returns>Inherited code: Requires comment 1.</returns> private static bool IsStar(DefinitionAbstraction definition) { if (definition.AsColumnDefinition != null) { return(definition.AsColumnDefinition.Width.IsStar); } return(definition.AsRowDefinition.Height.IsStar); }
/// <summary> /// Get the actual length of the given definition. /// </summary> /// <param name="definition"> /// Row or column definition to get the actual length for. /// </param> /// <returns> /// Height of a row definition or width of a column definition. /// </returns> private static double GetActualLength(DefinitionAbstraction definition) { if (definition.AsColumnDefinition != null) { return(definition.AsColumnDefinition.ActualWidth); } return(definition.AsRowDefinition.ActualHeight); }
/// <summary> /// Set the height/width of the given row/column. /// </summary> /// <param name="definition">Inherited code: Requires comment.</param> /// <param name="length">Inherited code: Requires comment 1.</param> private static void SetDefinitionLength(DefinitionAbstraction definition, GridLength length) { if (definition.AsColumnDefinition != null) { definition.AsColumnDefinition.SetValue(ColumnDefinition.WidthProperty, length); } else { definition.AsRowDefinition.SetValue(RowDefinition.HeightProperty, length); } }
/// <summary> /// Determine if the given definition has its size set to the "*" value /// </summary> private static bool IsStar(DefinitionAbstraction definition) { if (definition.AsColumnDefinition != null) { return definition.AsColumnDefinition.Width.IsStar; } return definition.AsRowDefinition.Height.IsStar; }
/// <summary> /// Set the height/width of the given row/column /// </summary> private static void SetDefinitionLength(DefinitionAbstraction definition, GridLength length) { if (definition.AsColumnDefinition != null) { definition.AsColumnDefinition.SetValue(ColumnDefinition.WidthProperty, length); } else { definition.AsRowDefinition.SetValue(RowDefinition.HeightProperty, length); } }
/// <summary> /// Set the lengths of the two definitions depending on the split behavior /// </summary> private void SetLengths(double definition1Pixels, double definition2Pixels) { if (_resizeData.SplitBehavior == SplitBehavior.Split) { IEnumerable enumerable = (_resizeData.ResizeDirection == GridResizeDirection.Columns) ? ((IEnumerable)_resizeData.Grid.ColumnDefinitions) : ((IEnumerable)_resizeData.Grid.RowDefinitions); int definitionIndex = 0; DefinitionAbstraction definitionAbstraction; foreach (DependencyObject definition in enumerable) { definitionAbstraction = new DefinitionAbstraction(definition); if (definitionIndex == _resizeData.Definition1Index) { SetDefinitionLength(definitionAbstraction, new GridLength(definition1Pixels, GridUnitType.Star)); } else if (definitionIndex == _resizeData.Definition2Index) { SetDefinitionLength(definitionAbstraction, new GridLength(definition2Pixels, GridUnitType.Star)); } else if (IsStar(definitionAbstraction)) { SetDefinitionLength(definitionAbstraction, new GridLength(GetActualLength(definitionAbstraction), GridUnitType.Star)); } definitionIndex++; } } else if (_resizeData.SplitBehavior == SplitBehavior.ResizeDefinition1) { SetDefinitionLength(_resizeData.Definition1, new GridLength(definition1Pixels)); } else { SetDefinitionLength(_resizeData.Definition2, new GridLength(definition2Pixels)); } }
/// <summary> /// Get the actual length of the given definition /// </summary> /// <param name="definition">Row or column definition to get the actual length for</param> /// <returns>Height of a row definition or width of a column definition</returns> private static double GetActualLength(DefinitionAbstraction definition) { if (definition.AsColumnDefinition != null) { return definition.AsColumnDefinition.ActualWidth; } return definition.AsRowDefinition.ActualHeight; }