.NET MAUI 导航动画

use*_*911 6 .net navigation animation maui

如果我想在 MAUI 中为从一个页面到另一页面的过渡设置动画,我需要使用true值激活它:

await Shell.Current.GoToAsync($"//{nameof(DashboardPage)}", true);
Run Code Online (Sandbox Code Playgroud)

这会动画化页面从右到左的过渡。有没有办法反转转换 => 从左到右?有什么建议么?我在 MAUI 文档中没有看到这个选项。有什么窍门吗?

Pou*_*tor 3

遇到了同样的问题,我最终使用自定义导航方法创建了一个自定义 ContentPage :

<ContentPage
Opacity="0"
x:Class="MauiTest.AnimatedPage"
x:Name="AnimatedContainer"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" />
Run Code Online (Sandbox Code Playgroud)

背后代码:

public partial class AnimatedPage : ContentPage
{
    public AnimatedPage()
    {
        InitializeComponent();

        AnimatedContainer.FadeTo(1, 100);
        AnimatedContainer.Content = Content;
    }

    public async Task AnimatedGoTo(string pUrl)
    {
        await AnimatedContainer.FadeTo(0, 100);
        await Shell.Current.GoToAsync(pUrl, true);
    }
}
Run Code Online (Sandbox Code Playgroud)

然后在每个应该动画的页面上:

<local:AnimatedPage
    Title="NewPage1"
    x:Class="MauiTest.NewPage1"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:local="clr-namespace:MauiTest"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
    <VerticalStackLayout>
        <Label
            HorizontalOptions="Center"
            Text="Welcome to .NET MAUI!"
            VerticalOptions="Center" />
        <Button
            Clicked="Button_Clicked"
            Text="Go back" />
    </VerticalStackLayout>
</local:AnimatedPage>
Run Code Online (Sandbox Code Playgroud)

背后代码:

public partial class NewPage1 : AnimatedPage
{
    public NewPage1()
    {
        InitializeComponent();
    }

    private void Button_Clicked(object sender, EventArgs e)
    {
        base.AnimatedGoTo("//main");
    }
}
Run Code Online (Sandbox Code Playgroud)

以此为基础,您可以使用任何基本动画进行过渡。