遇到了同样的问题,我最终使用自定义导航方法创建了一个自定义 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" />
背后代码:
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);
}
}
然后在每个应该动画的页面上:
<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>
背后代码:
public partial class NewPage1 : AnimatedPage
{
public NewPage1()
{
InitializeComponent();
}
private void Button_Clicked(object sender, EventArgs e)
{
base.AnimatedGoTo("//main");
}
}
以此为基础,您可以使用任何基础动画 https://learn.microsoft.com/en-us/dotnet/maui/user-interface/animation/basic?view=net-maui-7.0为您的过渡。