Example #1
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;
        }
Example #2
0
        public static void Init(
            Microsoft.UI.Xaml.LaunchActivatedEventArgs launchActivatedEventArgs,
            WindowsBasePage mainWindow,
            IEnumerable <Assembly> rendererAssemblies = null)
        {
            if (IsInitialized)
            {
                return;
            }

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

            Color.SetAccent(accent.ToFormsColor());

#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 (!Microsoft.UI.Xaml.Application.Current.Resources.ContainsKey("RootContainerStyle"))
            {
                Microsoft.UI.Xaml.Application.Current.Resources.MergedDictionaries.Add(GetTabletResources());
            }

            try
            {
                Microsoft.UI.Xaml.Application.Current.Resources.MergedDictionaries.Add(new Microsoft.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);
            Device.Info = new WindowsDeviceInfo();

            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;


            MainWindow = mainWindow;
            Microsoft.Maui.Controls.Compatibility.Forms.InitDispatcher(mainWindow.DispatcherQueue);
            mainWindow.LoadApplication(mainWindow.CreateApplication());
            mainWindow.Activate();
        }