You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET MAUI中点击按钮打开FlyoutPage导致应用退出问题求助

问题原因及解决方案

核心原因

FlyoutPage是.NET MAUI中的根级页面容器(类似TabbedPage),它的设计定位是作为应用的顶层页面,不能通过Navigation.PushAsync()方法推入导航栈。强行执行该操作会触发未捕获的异常,直接导致应用崩溃退出。

正确的实现方式

  • 如果要将FlyoutPage作为应用的初始页面,修改App.xaml.cs中的代码:
    public partial class App : Application
    {
        public App()
        {
            InitializeComponent();
            MainPage = new Flyout1(); // 直接设为根页面
        }
    }
    
  • 如果需要在运行时从现有页面切换到FlyoutPage,替换当前的根页面而非推入导航栈:
    private void FlyClicked(object sender, EventArgs e)
    {
        Application.Current.MainPage = new Flyout1();
    }
    

额外说明

如果需要在FlyoutPage内部进行页面导航,应该在FlyoutPage的Detail属性中设置一个NavigationPage,之后在Detail页面内部使用Navigation.PushAsync()来导航其他ContentPage。

内容的提问来源于stack exchange,提问作者Livio

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 08:30:50