Exemplo n.º 1
0
        /// <summary>
        /// Adds a handler for the specific visibility event
        /// </summary>
        /// <param name="visibilityEvent">The event to add a handler for</param>
        /// <param name="window">The window to add the handler for</param>
        /// <param name="handler">The handler</param>
        /// <returns>The WinRT handler</returns>
        private static WinRTVisibilityHandler AddVisibilityHandler(EventInfo visibilityEvent, Window window, TouchKeyboardVisibilityHandler handler)
        {
            IInputPane2 inputPane = GetInputPane(window);

            // This adds the event handler to the visibility event
            Func <WinRTVisibilityHandler, EventRegistrationToken> add =
                (addHandler) =>
            {
                return((EventRegistrationToken)visibilityEvent.AddMethod.Invoke(inputPane, new object[] { addHandler }));
            };

            // This removes the handler from the visibility event
            Action <EventRegistrationToken> remove =
                (removeHandler) =>
            {
                visibilityEvent.RemoveMethod.Invoke(inputPane, new object[] { removeHandler });
            };

            // This is the WinRT called handler to translate to the local WPF delegate
            WinRTVisibilityHandler localHandler =
                (inputPaneInstance, visArgs) =>
            {
                // We cannot reference System.Runtime.WindowsRuntime directly, so only access the Rect type via
                // reflection to ensure the proper assembly loads with no issues.
                var rect = visArgs.GetType().GetProperty("OccludedRect").GetValue(visArgs);

                // Invoke the WPF specific handler to pass the occluded rectangle information
                handler?.Invoke(
                    window,
                    new System.Windows.Rect(
                        (double)rect.GetType().GetRuntimeProperty("X").GetValue(rect),
                        (double)rect.GetType().GetRuntimeProperty("Y").GetValue(rect),
                        (double)rect.GetType().GetRuntimeProperty("Width").GetValue(rect),
                        (double)rect.GetType().GetRuntimeProperty("Height").GetValue(rect)));
            };

            // Add the event handlers
            WindowsRuntimeMarshal.AddEventHandler <WinRTVisibilityHandler>(add, remove, localHandler);

            // Return the WinRT handler in order to use it to un-register later
            return(localHandler);
        }
        /// <summary>
        /// Removes a handler for the specific visibility event
        /// </summary>
        /// <param name="visibilityEvent">The event to remove the handler for</param>
        /// <param name="window">The window to remove the handler for</param>
        /// <param name="winRtHandler">The WinRT handler</param>
        private static void RemoveVisibilityHandler(EventInfo visibilityEvent, Window window, WinRTVisibilityHandler winRtHandler)
        {
            IInputPane2 inputPane = GetInputPane(window);

            Action<EventRegistrationToken> remove =
                (removeHandler) =>
                {
                    visibilityEvent.RemoveMethod.Invoke(inputPane, new object[] { removeHandler });
                };

            WindowsRuntimeMarshal.RemoveEventHandler<WinRTVisibilityHandler>(remove, winRtHandler);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Removes a handler for the specific visibility event
        /// </summary>
        /// <param name="visibilityEvent">The event to remove the handler for</param>
        /// <param name="window">The window to remove the handler for</param>
        /// <param name="winRtHandler">The WinRT handler</param>
        private static void RemoveVisibilityHandler(EventInfo visibilityEvent, Window window, WinRTVisibilityHandler winRtHandler)
        {
            IInputPane2 inputPane = GetInputPane(window);

            Action <EventRegistrationToken> remove =
                (removeHandler) =>
            {
                visibilityEvent.RemoveMethod.Invoke(inputPane, new object[] { removeHandler });
            };

            WindowsRuntimeMarshal.RemoveEventHandler <WinRTVisibilityHandler>(remove, winRtHandler);
        }