Ejemplo n.º 1
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs e)
        {
            if (!String.IsNullOrWhiteSpace(e.Arguments) &&
                e.Arguments.Contains("RunningAsUITests"))
            {
                RunningAsUITests = true;
                ControlGallery.App.PreloadTestCasesIssuesList = false;
            }

            m_window = new MainPage();
            Maui.Controls.Compatibility.Forms.Init(e, m_window as MainPage);
        }
Ejemplo n.º 2
0
        public static IWindow?GetWindow(this UI.Xaml.Window nativeWindow)
        {
            foreach (var window in MauiWinUIApplication.Current.Application.Windows)
            {
                if (window?.Handler?.NativeView is UI.Xaml.Window win && win == nativeWindow)
                {
                    return(window);
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
        public static UI.Windowing.AppWindow?GetAppWindow(this UI.Xaml.Window platformWindow)
        {
            var hwnd = platformWindow.GetWindowHandle();

            if (hwnd == IntPtr.Zero)
            {
                return(null);
            }

            var windowId = UI.Win32Interop.GetWindowIdFromWindow(hwnd);

            return(UI.Windowing.AppWindow.GetFromWindowId(windowId));
        }
        internal void Subscribe(Window window)
        {
            IMauiContext mauiContext = window?.MauiContext;

            UI.Xaml.Window nativeWindow = mauiContext?.Window;

            if (Subscriptions.Any(s => s.Window == nativeWindow))
            {
                return;
            }

            Subscriptions.Add(new AlertRequestHelper(nativeWindow, mauiContext));
        }
        internal void Unsubscribe(Window window)
        {
            IMauiContext mauiContext = window?.MauiContext;

            UI.Xaml.Window nativeWindow = mauiContext?.Window;

            var toRemove = Subscriptions.Where(s => s.Window == nativeWindow).ToList();

            foreach (AlertRequestHelper alertRequestHelper in toRemove)
            {
                alertRequestHelper.Dispose();
                Subscriptions.Remove(alertRequestHelper);
            }
        }
Ejemplo n.º 6
0
 // TODO WINUI3 not sure the best way to detect the content swap out
 static void WireUpKeyDown(UI.Xaml.Window window)
 {
     window.DispatcherQueue.TryEnqueue(() =>
     {
         if (window.Content != null)
         {
             window.Content.KeyDown -= OnKeyDown;
             window.Content.KeyDown += OnKeyDown;
         }
         else
         {
             WireUpKeyDown(window);
         }
     });
 }
Ejemplo n.º 7
0
        public static void OnActivated(UI.Xaml.Window window, UI.Xaml.WindowActivatedEventArgs e)
        {
            // When the native control gallery loads up, it'll let us know so we can add the nested native controls
            MessagingCenter.Subscribe <NestedNativeControlGalleryPage>(window, NestedNativeControlGalleryPage.ReadyForNativeControlsMessage, AddNativeControls);

            // When the native binding gallery loads up, it'll let us know so we can set up the native bindings
            MessagingCenter.Subscribe <NativeBindingGalleryPage>(window, NativeBindingGalleryPage.ReadyForNativeBindingsMessage, AddNativeBindings);

            Application.Current.PropertyChanged += OnAppPropertyChanged;

            WireUpKeyDown(window);

            void OnAppPropertyChanged(object sender, global::System.ComponentModel.PropertyChangedEventArgs e)
            {
                if (e.PropertyName == nameof(Application.MainPage))
                {
                    WireUpKeyDown(window);
                }
            }
        }
Ejemplo n.º 8
0
        static void SetupInit(
            IMauiContext mauiContext,
            UI.Xaml.Window 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.ToColor());

            Device.SetFlowDirection(mauiContext.GetFlowDirection());

            ExpressionSearch.Default = new WindowsExpressionSearch();

            Registrar.ExtraAssemblies = rendererAssemblies?.ToArray();

            var platformServices = new WindowsPlatformServices();

            Device.PlatformServices = platformServices;

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

                //if (mainWindow is WindowsBasePage windowsPage)
                //{
                //	windowsPage.LoadApplication(windowsPage.CreateApplication());
                //	windowsPage.Activate();
                //}
            }

            IsInitialized = true;
        }
Ejemplo n.º 9
0
    public static IntPtr GetNativeWindowHandle(this UI.Xaml.Window window)
    {
        var nativeWindow = window.As <IWindowNative>();

        return(nativeWindow.WindowHandle);
    }
Ejemplo n.º 10
0
 public static Task <IScreenshotResult> CaptureAsync(this IScreenshot screenshot, UI.Xaml.Window window) =>
 screenshot.AsPlatform().CaptureAsync(window);
Ejemplo n.º 11
0
 public static void UpdateTitle(this UI.Xaml.Window nativeWindow, IWindow window) =>
 nativeWindow.Title = window.Title;
Ejemplo n.º 12
0
 public static void SetWindowHandler(this UI.Xaml.Window nativeWindow, IWindow window, IMauiContext context) =>
 SetHandler(nativeWindow, window, context);
Ejemplo n.º 13
0
 public MauiContext(IServiceProvider services, UI.Xaml.Window window)
     : this(services)
 {
     Window = window ?? throw new ArgumentNullException(nameof(window));
 }
Ejemplo n.º 14
0
        static void SetupInit(
            IMauiContext mauiContext,
            UI.Xaml.Window 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.ToColor());

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

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

            Device.SetFlags(s_flags);
            Device.Info = new WindowsDeviceInfo();

            //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();

            var dispatcher = mainWindow?.DispatcherQueue ?? UI.Dispatching.DispatcherQueue.GetForCurrentThread();

            var platformServices = new WindowsPlatformServices(dispatcher);

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

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

                //if (mainWindow is WindowsBasePage windowsPage)
                //{
                //	windowsPage.LoadApplication(windowsPage.CreateApplication());
                //	windowsPage.Activate();
                //}
            }

            IsInitialized = true;
        }
Ejemplo n.º 15
0
 public static void Init(
     UI.Xaml.Window mainWindow,
     IEnumerable <Assembly> rendererAssemblies = null)
 {
     SetupInit(new MauiContext(), mainWindow, rendererAssemblies);
 }