Navigate to page on start in .NET Maui app

Navigate to page on start in .NET Maui app

https://stackoverflow.com/questions/73840141/navigate-to-page-on-start-in-net-maui-app

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
public partial class App : Application
{
    public App()
    {
        InitializeComponent();
        ICollection<ResourceDictionary> mergedDictionaries = Application.Current.Resources.MergedDictionaries;
        Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Ngo9BigBOggjHTQxAR8/V1NHaF1cWWhIfEx1RHxQdld5ZFRHallYTnNWUj0eQnxTdEZiW35ccHdQR2VcUEN/Xw==");
        //Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Ngo9BigBOggjHTQxAR8/V1NGaF1cWGhIfEx1RHxQdld5ZFRHallYTnNWUj0eQnxTdEZjUX5acHdRQ2JUWEd0Xg==");
        //if (Config.Desktop)
        //    MainPage = new DesktopShell();
        //else
        //    MainPage = new MobileShell();
    }

    protected override Window CreateWindow(IActivationState activationState)
    {
        MauiExceptions.UnhandledException += (sender, args) =>
        {
            Exception? exception = args.ExceptionObject as Exception;
        };

        var size = WindowControl.GetOprationSystemResolution();
        if (Config.Desktop)
        {
            int width = 1380;
            int height = 768;

            return new Window(new DesktopShell())
            {
                Width = width,
                Height = height,
                X = (size.Width - width) / 2,
                Y = (size.Height - height) / 2
            };
        }                
        else
            return new Window(new MobileShell())
            {
                Width = 700,
                Height = 500,
                X = 100,
                Y = 100
            };
    }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using MyApp.Services;
using MyApp.UI;

namespace MyApp;

public partial class App : Application
{
    ConfigurationProviderService m_configProvider;

    public App(ConfigurationProviderService configProvider)
    {
        m_configProvider = configProvider;

        InitializeComponent();

        MainPage = new LoadingPage();
    }

    protected override void OnStart()
    {
        var task = InitAsync();

        task.ContinueWith((task) =>
        {
            MainThread.BeginInvokeOnMainThread(() =>
            {
                MainPage = new AppShell();

                // Choose navigation depending on init
                Shell.Current.GoToAsync(...);
            });
        });

        base.OnStart();
    }

    private async Task InitAsync()
    {
        await m_configProvider.InitAsync();
    }
}
Licensed under CC BY-NC-SA 4.0
Built with Hugo
Theme Stack designed by Jimmy