Esempio n. 1
0
        protected override void OnLaunched(UI.Xaml.LaunchActivatedEventArgs args)
        {
            // Windows running on a different thread will "launch" the app again
            if (Application != null)
            {
                Services.InvokeLifecycleEvents <WindowsLifecycle.OnLaunching>(del => del(this, args));
                Services.InvokeLifecycleEvents <WindowsLifecycle.OnLaunched>(del => del(this, args));
                return;
            }

            var mauiApp = CreateMauiApp();

            var rootContext = new MauiContext(mauiApp.Services);

            var applicationContext = rootContext.MakeApplicationScope(this);

            Services = applicationContext.Services;

            Services.InvokeLifecycleEvents <WindowsLifecycle.OnLaunching>(del => del(this, args));

            Application = Services.GetRequiredService <IApplication>();

            this.SetApplicationHandler(Application, applicationContext);

            this.CreateNativeWindow(Application, args);

            Services.InvokeLifecycleEvents <WindowsLifecycle.OnLaunched>(del => del(this, args));
        }
Esempio n. 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.View;

            var canvas = CreateRootContainer();

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

            MainWindow.Content = canvas;

            MainWindow.Activate();
        }
Esempio n. 3
0
 public static void Init(
     UI.Xaml.LaunchActivatedEventArgs launchActivatedEventArgs,
     WindowsBasePage mainWindow,
     IEnumerable <Assembly> rendererAssemblies = null)
 {
     SetupInit(new MauiContext(), launchActivatedEventArgs, mainWindow, rendererAssemblies);
 }
Esempio n. 4
0
 public ActivationState(
     IMauiContext context,
     UI.Xaml.LaunchActivatedEventArgs launchActivatedEventArgs)
 {
     Context = context;
     LaunchActivatedEventArgs = launchActivatedEventArgs;
 }
Esempio n. 5
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();
        }
        protected override void OnLaunched(UI.Xaml.LaunchActivatedEventArgs args)
        {
            LaunchActivatedEventArgs = args;

            var mauiApp = CreateMauiApp();

            Services = mauiApp.Services;

            Services.InvokeLifecycleEvents <WindowsLifecycle.OnLaunching>(del => del(this, args));

            Application = Services.GetRequiredService <IApplication>();

            var winuiWndow = CreateNativeWindow(args);

            MainWindow = winuiWndow;

            MainWindow.Activate();

            Services.InvokeLifecycleEvents <WindowsLifecycle.OnLaunched>(del => del(this, args));
        }
Esempio n. 7
0
        static void SetupInit(
            IMauiContext mauiContext,
            UI.Xaml.LaunchActivatedEventArgs launchActivatedEventArgs,
            WindowsBasePage mainWindow,
            IEnumerable <Assembly> rendererAssemblies = null,
            InitializationOptions?maybeOptions        = null)
        {
            MauiContext = mauiContext;
            Registrar.RegisterRendererToHandlerShim(RendererToHandlerShim.CreateShim);

            var accent = (WSolidColorBrush)Microsoft.UI.Xaml.Application.Current.Resources["SystemColorControlAccentBrush"];

            KnownColor.SetAccent(accent.ToFormsColor());

            if (!IsInitialized)
            {
#if !UWP_16299
                Log.Listeners.Add(new DelegateLogListener((c, m) => Debug.WriteLine(LogFormat, c, m)));
#else
                Log.Listeners.Add(new DelegateLogListener((c, m) => Trace.WriteLine(m, c)));
#endif
            }

            if (!UI.Xaml.Application.Current.Resources.ContainsKey("RootContainerStyle"))
            {
                UI.Xaml.Application.Current.Resources.MergedDictionaries.Add(GetTabletResources());
            }

            try
            {
                UI.Xaml.Application.Current.Resources.MergedDictionaries.Add(new UI.Xaml.Controls.XamlControlsResources());
            }
            catch
            {
                Log.Warning("Resources", "Unable to load WinUI resources. Try adding Microsoft.Maui.Controls.Compatibility nuget to UWP project");
            }

            Device.SetIdiom(TargetIdiom.Tablet);
            Device.SetFlowDirection(GetFlowDirection());

            Device.SetFlags(s_flags);

            //TODO WINUI3
            //// use field and not property to avoid exception in getter
            //if (Device.info != null)
            //{
            //	Device.info.Dispose();
            //	Device.info = null;
            //}
            //Device.Info = new WindowsDeviceInfo();

            //TODO WINUI3
            //switch (Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily)
            //{
            //	case "Windows.Desktop":
            //		if (Windows.UI.ViewManagement.UIViewSettings.GetForCurrentView().UserInteractionMode ==
            //			Windows.UI.ViewManagement.UserInteractionMode.Touch)
            //			Device.SetIdiom(TargetIdiom.Tablet);
            //		else
            //			Device.SetIdiom(TargetIdiom.Desktop);
            //		break;
            //	case "Windows.Mobile":
            //		Device.SetIdiom(TargetIdiom.Phone);
            //		break;
            //	case "Windows.Xbox":
            //		Device.SetIdiom(TargetIdiom.TV);
            //		break;
            //	default:
            //		Device.SetIdiom(TargetIdiom.Unsupported);
            //		break;
            //}

            ExpressionSearch.Default = new WindowsExpressionSearch();

            Registrar.ExtraAssemblies = rendererAssemblies?.ToArray();
            s_state = launchActivatedEventArgs.UWPLaunchActivatedEventArgs.PreviousExecutionState;

            var dispatcher = mainWindow?.DispatcherQueue ?? System.DispatcherQueue.GetForCurrentThread();

            var platformServices = new WindowsPlatformServices(dispatcher);

            Device.PlatformServices    = platformServices;
            Device.PlatformInvalidator = platformServices;

            if (maybeOptions?.Flags.HasFlag(InitializationFlags.SkipRenderers) != true)
            {
                RegisterCompatRenderers();
            }

            if (mainWindow != null)
            {
                MainWindow = mainWindow;

                //TODO WINUI3
                Platform.UWP.Platform.SubscribeAlertsAndActionSheets();

                mainWindow.LoadApplication(mainWindow.CreateApplication());
                mainWindow.Activate();
            }

            IsInitialized = true;
        }
Esempio n. 8
0
 public InitializationOptions(UI.Xaml.LaunchActivatedEventArgs args)
 {
     this = default(InitializationOptions);
     LaunchActivatedEventArgs = args;
 }
Esempio n. 9
0
 public static Task OnLaunched(this IAppActions appActions, UI.Xaml.LaunchActivatedEventArgs e) =>
 appActions.AsPlatform().OnLaunched(e);