Пример #1
0
        protected override void OnLaunched(UI.Xaml.LaunchActivatedEventArgs args)
        {
            LaunchActivatedEventArgs = args;

            // TODO: This should not be here. CreateWindow should do it.
            MainWindow = new MauiWinUIWindow();

            var startup = new TStartup();

            var host = startup
                       .CreateAppHostBuilder()
                       .ConfigureServices(ConfigureNativeServices)
                       .ConfigureUsing(startup)
                       .Build();

            Services    = host.Services;
            Application = Services.GetRequiredService <IApplication>();

            var mauiContext = new MauiContext(Services);

            var activationState = new ActivationState(mauiContext, args);
            var window          = Application.CreateWindow(activationState);

            window.MauiContext = mauiContext;

            var content = (window.Page as IView) ?? window.Page.View;

            var canvas = CreateRootContainer();

            canvas.Children.Add(content.ToNative(window.MauiContext));

            MainWindow.Content = canvas;

            MainWindow.Activate();
        }
Пример #2
0
        protected override void OnLaunched(UI.Xaml.LaunchActivatedEventArgs args)
        {
            LaunchActivatedEventArgs = args;

            // TODO: This should not be here. CreateWindow should do it.
            MainWindow = new MauiWinUIWindow();

            var startup = new TStartup();

            var host = startup
                       .CreateAppHostBuilder()
                       .ConfigureServices(ConfigureNativeServices)
                       .ConfigureUsing(startup)
                       .Build();

            Services    = host.Services;
            Application = Services.GetRequiredService <IApplication>();

            var mauiContext = new MauiContext(Services);

            var activationState = new ActivationState(mauiContext, args);
            var window          = Application.CreateWindow(activationState);

            window.MauiContext = mauiContext;

            var content = (window.Page as IView) ?? window.Page.Content;

            var canvas = CreateRootContainer();

            var nativeContent = content.ToNative(window.MauiContext);

            canvas.Children.Add(nativeContent);

            MainWindow.Content = canvas;

            Current.Services?.InvokeLifecycleEvents <WindowsLifecycle.OnLaunched>(del => del(this, args));

            MainWindow.SizeChanged += (sender, sizeChangedArgs) =>
            {
                // TODO ezhart We need a better signalling mechanism between the PagePanel and the ContentPage for invalidation
                content.InvalidateMeasure();

                // TODO ezhart This is not ideal, but we need to force the canvas to match the window size
                // We probably need a better root control than Canvas, really
                canvas.Width  = MainWindow.Bounds.Width;
                canvas.Height = MainWindow.Bounds.Height;

                // TODO ezhart Once we've got navigation up and running, this will need to be updated so it
                // affects the navigation root or the current page. Again, Canvas is probably not the right root, but
                // I haven't been able to get a custom Panel to handle the drawing correctly yet.
                nativeContent.Width  = canvas.ActualWidth;
                nativeContent.Height = canvas.ActualHeight;
            };

            MainWindow.Activate();
        }