Skip to content

Commit

Permalink
Legacy measure methods deprecated (#2596)
Browse files Browse the repository at this point in the history
* Add xrefs.

* Edits.
  • Loading branch information
davidbritch authored Nov 1, 2024
1 parent 408aa45 commit e375b22
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/user-interface/layouts/custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public override Size Measure(double widthConstraint, double heightConstraint)
}
```

The `Measure` method enumerates through all of the visible children in the layout, invoking the <xref:Microsoft.Maui.IView.Measure%2A?displayProperty=nameWithType> method on each child. It then returns the total size of the layout, taking into account the constraints and the values of the <xref:Microsoft.Maui.Controls.Layout.Padding> and <xref:Microsoft.Maui.Controls.StackBase.Spacing> properties. The <xref:Microsoft.Maui.Layouts.LayoutManager.ResolveConstraints%2A> method is called to ensure that the total size of the layout fits within its constraints.
The <xref:Microsoft.Maui.Controls.VisualElement.Measure(System.Double,System.Double)> method enumerates through all of the visible children in the layout, invoking the <xref:Microsoft.Maui.IView.Measure%2A?displayProperty=nameWithType> method on each child. It then returns the total size of the layout, taking into account the constraints and the values of the <xref:Microsoft.Maui.Controls.Layout.Padding> and <xref:Microsoft.Maui.Controls.StackBase.Spacing> properties. The <xref:Microsoft.Maui.Layouts.LayoutManager.ResolveConstraints%2A> method is called to ensure that the total size of the layout fits within its constraints.

> [!IMPORTANT]
> When enumerating children in the <xref:Microsoft.Maui.Layouts.ILayoutManager.Measure%2A?displayProperty=nameWithType> implementation, skip any child whose <xref:Microsoft.Maui.IView.Visibility> property is set to <xref:Microsoft.Maui.Visibility.Collapsed>. This ensures that the custom layout won't leave space for invisible children.
Expand Down
16 changes: 7 additions & 9 deletions docs/whats-new/dotnet-9.md
Original file line number Diff line number Diff line change
Expand Up @@ -475,22 +475,20 @@ The `MainPage` property is retained for .NET MAUI 9, but will be completely remo

### Compatibility layouts

The compatibility layout classes in the `Microsoft.Maui.Controls.Compatibility` namespace have been obsoleted.
The compatibility layout classes in the <xref:Microsoft.Maui.Controls.Compatibility> namespace have been obsoleted.

### Legacy measure calls

The following `VisualElement` legacy measure methods have been obsoleted:
The following <xref:Microsoft.Maui.Controls.VisualElement> measure methods have been obsoleted:

- `protected override SizeRequest OnMeasure(double widthConstraint, double heightConstraint)`.
- `public virtual SizeRequest Measure(double widthConstraint, double heightConstraint, MeasureFlags flags = MeasureFlags.None)` from `VisualElement`.
- <xref:Microsoft.Maui.Controls.VisualElement.OnMeasure%2A?displayProperty=nameWithType>
- <xref:Microsoft.Maui.Controls.VisualElement.Measure(System.Double,System.Double,Microsoft.Maui.Controls.MeasureFlags)?displayProperty=nameWithType>

As a replacement, the following method has been introduced:
These are legacy measure methods that don't function correctly with .NET MAUI layout expectations.

- `public size Measure(double widthConstraint, double heightConstraint)`
As a replacement, the <xref:Microsoft.Maui.Controls.VisualElement.Measure(System.Double,System.Double)?displayProperty=nameWithType> method has been introduced. This method returns the minimum size that an element needs in order to be displayed on a device. Margins are excluded from the measurement, but are returned with the size. This is the preferred method to call when measuring a view.

This `Measure` method returns the minimum size that an element needs in order to be displayed on a device. Margins are excluded from the measurement, but are returned with the size. This is the preferred method to call when measuring a view.

In addition, the `Microsoft.Maui.SizeRequest` struct is obsoleted. Instead, `Microsoft.Maui.Size` should be used.
In addition, the <xref:Microsoft.Maui.SizeRequest> struct is obsoleted. Instead, <xref:Microsoft.Maui.Graphics.Size> should be used.

## .NET for Android

Expand Down

0 comments on commit e375b22

Please sign in to comment.