/// <summary> /// <see cref="PropertyMetadata.PropertyChangedCallback"/> /// </summary> /// <remarks> /// This method needs to be internal to be accessable from derived classes. /// </remarks> internal static void OnUserMaxSizePropertyChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e) { DefinitionBase definition = (DefinitionBase)d; if (definition.InParentLogicalTree) { Grid parentGrid = (Grid)definition.Parent; parentGrid.InvalidateMeasure(); } }
public void Calculates_Colspan_Correctly() { var target = new Grid { ColumnDefinitions = new ColumnDefinitions { new ColumnDefinition(GridLength.Auto), new ColumnDefinition(new GridLength(4, GridUnitType.Pixel)), new ColumnDefinition(GridLength.Auto), }, RowDefinitions = new RowDefinitions { new RowDefinition(GridLength.Auto), new RowDefinition(GridLength.Auto), }, Children = new Controls { new Border { Width = 100, Height = 25, [Grid.ColumnSpanProperty] = 3, }, new Border { Width = 150, Height = 25, [Grid.RowProperty] = 1, }, new Border { Width = 50, Height = 25, [Grid.RowProperty] = 1, [Grid.ColumnProperty] = 2, } }, }; target.Measure(Size.Infinity); // Issue #25 only appears after a second measure target.InvalidateMeasure(); target.Measure(Size.Infinity); target.Arrange(new Rect(target.DesiredSize)); Assert.Equal(new Size(204, 50), target.Bounds.Size); Assert.Equal(150d, target.ColumnDefinitions[0].ActualWidth); Assert.Equal(4d, target.ColumnDefinitions[1].ActualWidth); Assert.Equal(50d, target.ColumnDefinitions[2].ActualWidth); Assert.Equal(new Rect(52, 0, 100, 25), target.Children[0].Bounds); Assert.Equal(new Rect(0, 25, 150, 25), target.Children[1].Bounds); Assert.Equal(new Rect(154, 25, 50, 25), target.Children[2].Bounds); }
/// <summary> /// OnLayoutUpdated handler. Validates that all participating definitions /// have updated min size value. Forces another layout update cycle if needed. /// </summary> private void OnLayoutUpdated(object sender, EventArgs e) { double sharedMinSize = 0; // accumulate min size of all participating definitions for (int i = 0, count = _registry.Count; i < count; ++i) { sharedMinSize = Math.Max(sharedMinSize, _registry[i].MinSize); } bool sharedMinSizeChanged = !MathUtilities.AreClose(_minSize, sharedMinSize); // compare accumulated min size with min sizes of the individual definitions for (int i = 0, count = _registry.Count; i < count; ++i) { DefinitionBase definitionBase = _registry[i]; if (sharedMinSizeChanged || definitionBase.LayoutWasUpdated) { // if definition's min size is different, then need to re-measure if (!MathUtilities.AreClose(sharedMinSize, definitionBase.MinSize)) { Grid parentGrid = (Grid)definitionBase.Parent; parentGrid.InvalidateMeasure(); definitionBase.UseSharedMinimum = true; } else { definitionBase.UseSharedMinimum = false; // if measure is valid then also need to check arrange. // Note: definitionBase.SizeCache is volatile but at this point // it contains up-to-date final size if (!MathUtilities.AreClose(sharedMinSize, definitionBase.SizeCache)) { Grid parentGrid = (Grid)definitionBase.Parent; parentGrid.InvalidateArrange(); } } definitionBase.LayoutWasUpdated = false; } } _minSize = sharedMinSize; _layoutUpdatedHost.LayoutUpdated -= _layoutUpdated; _layoutUpdatedHost = null; _broadcastInvalidation = true; }