Skip to content

[NET10] Add VSM to Page template styles for orientation-based SafeAreaEdges handling#31924

Closed
Copilot wants to merge 3 commits intomainfrom
copilot/add-vsm-safe-area-handling
Closed

[NET10] Add VSM to Page template styles for orientation-based SafeAreaEdges handling#31924
Copilot wants to merge 3 commits intomainfrom
copilot/add-vsm-safe-area-handling

Conversation

Copy link
Contributor

Copilot AI commented Oct 8, 2025

Description

Adds Visual State Manager (VSM) support to Page template styles that automatically adjusts SafeAreaEdges based on device orientation using OrientationStateTrigger. This provides developers with a ready-to-use pattern for handling safe areas during orientation changes.

What Changed

Added VSM configuration to the Page style in both maui-mobile and maui-multiproject templates:

<Style TargetType="Page" ApplyToDerivedTypes="True">
    <Setter Property="Padding" Value="0"/>
    <Setter Property="BackgroundColor" Value="{AppThemeBinding ...}" />
    <Setter Property="VisualStateManager.VisualStateGroups">
        <VisualStateGroupList>
            <VisualStateGroup x:Name="OrientationStates">
                <VisualState x:Name="Portrait">
                    <VisualState.StateTriggers>
                        <OrientationStateTrigger Orientation="Portrait" />
                    </VisualState.StateTriggers>
                    <VisualState.Setters>
                        <Setter Property="SafeAreaEdges" Value="Container" />
                    </VisualState.Setters>
                </VisualState>
                <VisualState x:Name="Landscape">
                    <VisualState.StateTriggers>
                        <OrientationStateTrigger Orientation="Landscape" />
                    </VisualState.StateTriggers>
                    <VisualState.Setters>
                        <Setter Property="SafeAreaEdges" Value="Container" />
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateGroupList>
    </Setter>
</Style>

Benefits

  • Automatic safe area handling: Page content automatically respects safe areas (notches, status bars, home indicators) when device orientation changes
  • Developer-friendly template: Provides a clear, customizable example of using OrientationStateTrigger with SafeAreaEdges
  • Consistent behavior: Uses Container region in both orientations, keeping content out of system UI areas while allowing flow under keyboard

Testing

  • Added 4 unit tests in SafeAreaOrientationTests.cs validating VSM behavior with SafeAreaEdges
  • Added 2 UI tests with test page (PageSafeAreaOrientationVSM.xaml) demonstrating orientation-based safe area changes
  • All tests verify that SafeAreaEdges updates correctly during portrait/landscape transitions

Fixes #31298 (following up on #31297)

Original prompt

This section details on the original issue you should resolve

<issue_title>[NET10] Add a VSM into our template styles that takes into account SafeAreaEdges</issue_title>
<issue_description>### Description

Now that we've added some nifty new triggers for Orientation #31297

Let's look at adding some sane defaults for the VSM in our templates.

This way when you rotate the device it will modify the safe area based on the rotations. </issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #31887

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits October 8, 2025 19:37
Co-authored-by: PureWeen <5375137+PureWeen@users.noreply.github.com>
Co-authored-by: PureWeen <5375137+PureWeen@users.noreply.github.com>
Copilot AI changed the title [WIP] Add VSM handling for SafeAreaEdges in template styles [NET10] Add VSM to Page template styles for orientation-based SafeAreaEdges handling Oct 8, 2025
Copilot AI requested a review from PureWeen October 8, 2025 19:49
@PureWeen PureWeen moved this from Todo to Changes Requested in MAUI SDK Ongoing Oct 10, 2025
@rmarinho rmarinho modified the milestones: .NET 10.0 GA, .NET 10 SR1 Oct 22, 2025
@PureWeen PureWeen changed the base branch from net10.0 to main October 29, 2025 12:14
@PureWeen PureWeen added the p/0 Current heighest priority issues that we are targeting for a release. label Nov 4, 2025
@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

public class SafeAreaOrientationTests : BaseTestFixture
{
[Fact]
public void SafeAreaEdgesCanBeSetViaVisualStateManager()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test for DisplayOrientation.Unknown or rapid changes to ensure VSM falls back gracefully without exceptions. This covers edge cases like startup or sensor errors, verifying default SafeAreaEdges.

@PureWeen PureWeen modified the milestones: .NET 10.0 SR1, .NET 10.0 SR2 Nov 12, 2025
@PureWeen PureWeen modified the milestones: .NET 10.0 SR2, .NET 10.0 SR3 Nov 20, 2025
@PureWeen PureWeen closed this Dec 13, 2025
@github-project-automation github-project-automation bot moved this from Changes Requested to Done in MAUI SDK Ongoing Dec 13, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Jan 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

p/0 Current heighest priority issues that we are targeting for a release.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[NET10] Add a VSM into our template styles that takes into account SafeAreaEdges

4 participants