Exemple #1
0
        /// <summary>
        /// Creates a WpfHost element to host a Uno-Skia into a WPF application.
        /// </summary>
        /// <remarks>
        /// If args are omitted, those from Environment.GetCommandLineArgs() will be used.
        /// </remarks>
        public WpfHost(global::System.Windows.Threading.Dispatcher dispatcher, Func <WinUI.Application> appBuilder, string[] args = null)
        {
            _current = this;

            args ??= Environment
            .GetCommandLineArgs()
            .Skip(1)
            .ToArray();

            designMode = DesignerProperties.GetIsInDesignMode(this);

            void CreateApp(WinUI.ApplicationInitializationCallbackParams _)
            {
                var app = appBuilder();

                app.Host = this;
            }

            Windows.UI.Core.CoreDispatcher.DispatchOverride
                = d => dispatcher.BeginInvoke(d);

            WinUI.Application.Start(CreateApp, args);

            WinUI.Window.InvalidateRender += () => InvalidateVisual();

            SizeChanged += WpfHost_SizeChanged;
            Loaded      += WpfHost_Loaded;
        }
Exemple #2
0
        public WpfHost(global::System.Windows.Threading.Dispatcher dispatcher, Func <WinUI.Application> appBuilder, string[] args = null)
        {
            _current = this;

            args ??= Environment
            .GetCommandLineArgs()
            .Skip(1)
            .ToArray();

            designMode = DesignerProperties.GetIsInDesignMode(this);

            void CreateApp(WinUI.ApplicationInitializationCallbackParams _)
            {
                var app = appBuilder();

                app.Host = this;
            }

            bool EnqueueNative(DispatcherQueuePriority priority, DispatcherQueueHandler callback)
            {
                if (priority == DispatcherQueuePriority.Normal)
                {
                    dispatcher.BeginInvoke(callback);
                }
                else
                {
                    var p = priority switch
                    {
                        DispatcherQueuePriority.Low => DispatcherPriority.Background,
                        DispatcherQueuePriority.High => DispatcherPriority.Send,                         // This one is higher than normal
                        _ => DispatcherPriority.Normal
                    };
                    dispatcher.BeginInvoke(p, callback);
                }

                return(true);
            }

            Windows.System.DispatcherQueue.EnqueueNativeOverride = EnqueueNative;

            Windows.UI.Core.CoreDispatcher.DispatchOverride        = d => dispatcher.BeginInvoke(d);
            Windows.UI.Core.CoreDispatcher.HasThreadAccessOverride = dispatcher.CheckAccess;

            WinUI.Application.Start(CreateApp, args);

            WinUI.Window.InvalidateRender += () =>
            {
                InvalidateFocusVisual();
                InvalidateVisual();
            };

            WpfApplication.Current.Activated               += Current_Activated;
            WpfApplication.Current.Deactivated             += Current_Deactivated;
            WpfApplication.Current.MainWindow.StateChanged += MainWindow_StateChanged;

            SizeChanged += WpfHost_SizeChanged;
            Loaded      += WpfHost_Loaded;
        }
Exemple #3
0
        public WpfHost(global::System.Windows.Threading.Dispatcher dispatcher, Func <WinUI.Application> appBuilder, string[] args = null)
        {
            _current = this;

            args ??= Environment
            .GetCommandLineArgs()
            .Skip(1)
            .ToArray();

            designMode = DesignerProperties.GetIsInDesignMode(this);

            void CreateApp(WinUI.ApplicationInitializationCallbackParams _)
            {
                var app = appBuilder();

                app.Host = this;
            }

            Windows.UI.Core.CoreDispatcher.DispatchOverride        = d => dispatcher.BeginInvoke(d);
            Windows.UI.Core.CoreDispatcher.HasThreadAccessOverride = dispatcher.CheckAccess;

            WinUI.Application.Start(CreateApp, args);

            WinUI.Window.InvalidateRender += () =>
            {
                InvalidateOverlays();
                InvalidateVisual();
            };

            WpfApplication.Current.Activated               += Current_Activated;
            WpfApplication.Current.Deactivated             += Current_Deactivated;
            WpfApplication.Current.MainWindow.StateChanged += MainWindow_StateChanged;
            WpfApplication.Current.MainWindow.Closing      += MainWindow_Closing;

            Windows.Foundation.Size preferredWindowSize = ApplicationView.PreferredLaunchViewSize;
            if (preferredWindowSize != Windows.Foundation.Size.Empty)
            {
                WpfApplication.Current.MainWindow.Width  = (int)preferredWindowSize.Width;
                WpfApplication.Current.MainWindow.Height = (int)preferredWindowSize.Height;
            }

            SizeChanged += WpfHost_SizeChanged;
            Loaded      += WpfHost_Loaded;
        }