Maui程序Shell使用MVVM

Maui程序Shell使用MVVM

  1. 注册服务

    1
    
    services.AddSingleton<AppShell, ShellViewModel>();
    
  2. 修改App.xaml.cs

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    
    public App()
    {
        InitializeComponent();
    
        MauiExceptions.UnhandledException += (sender, args) =>
        {
            Exception? exception = args.ExceptionObject as Exception;
        };
    }
    protected override Window CreateWindow(IActivationState? activationState)
    {
        AppShell? appShell = activationState?.Context.Services.GetService<AppShell>();
        Window window = new(appShell!);
        return window;
    }
    
Licensed under CC BY-NC-SA 4.0
Built with Hugo
Theme Stack designed by Jimmy