Ejemplo n.º 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;
        }
Ejemplo n.º 2
0
        public WpfUIElementPointersSupport(object owner)
        {
            _ownerEvents = (ICoreWindowEvents)owner;

            _host = WpfHost.Current;

            _host.MouseEnter += HostOnMouseEnter;
            _host.MouseLeave += HostOnMouseLeave;
            _host.MouseMove  += HostOnMouseMove;
            _host.MouseDown  += HostOnMouseDown;
            _host.MouseUp    += HostOnMouseUp;

            // Hook for native events
            _host.Loaded += HookNative;

            void HookNative(object sender, RoutedEventArgs e)
            {
                _host.Loaded -= HookNative;

                var win = Window.GetWindow(_host);
                var fromDependencyObject = PresentationSource.FromDependencyObject(win);

                _hwndSource = fromDependencyObject as HwndSource;
                _hwndSource?.AddHook(OnWmMessage);
            }
        }
Ejemplo n.º 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;
            }

            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;
        }
Ejemplo n.º 4
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;
        }