Ejemplo n.º 1
0
        private static void WindowActivating(object sender, WindowActivateEventArgs e)
        {
            IntPtr intPtr;

            if (Keyboard.FocusedElement == null && FocusElementManager._lastFocusedElement != null && FocusElementManager._lastFocusedElement.IsAlive)
            {
                ILayoutElement target = FocusElementManager._lastFocusedElement.Target as ILayoutElement;
                if (target != null)
                {
                    DockingManager manager = target.Root.Manager;
                    if (manager == null)
                    {
                        return;
                    }
                    if (!manager.GetParentWindowHandle(out intPtr))
                    {
                        return;
                    }
                    if (e.HwndActivating != intPtr)
                    {
                        return;
                    }
                    FocusElementManager._setFocusAsyncOperation = Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => {
                        try
                        {
                            FocusElementManager.SetFocusOnLastElement(target);
                        }
                        finally
                        {
                            FocusElementManager._setFocusAsyncOperation = null;
                        }
                    }), DispatcherPriority.Input, new object[0]);
                }
            }
        }
        static void WindowActivating(object sender, WindowActivateEventArgs e)
        {
            Trace.WriteLine("WindowActivating");

            if (Keyboard.FocusedElement == null &&
                _lastFocusedElement != null &&
                _lastFocusedElement.IsAlive)
            {
                var elementToSetFocus = _lastFocusedElement.Target as ILayoutElement;
                if (elementToSetFocus != null)
                {
                    var manager = elementToSetFocus.Root.Manager;
                    if (manager == null)
                    {
                        return;
                    }

                    IntPtr parentHwnd;
                    if (!manager.GetParentWindowHandle(out parentHwnd))
                    {
                        return;
                    }

                    if (e.HwndActivating != parentHwnd)
                    {
                        return;
                    }

                    _setFocusAsyncOperation = Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
                    {
                        try
                        {
                            SetFocusOnLastElement(elementToSetFocus);
                        }
                        finally
                        {
                            _setFocusAsyncOperation = null;
                        }
                    }), DispatcherPriority.Background);
                }
            }
        }
        static void WindowActivating(object sender, WindowActivateEventArgs e)
        {
            if (Keyboard.FocusedElement == null && 
                _lastFocusedElement != null && 
                _lastFocusedElement.IsAlive)
            {
                var elementToSetFocus = _lastFocusedElement.Target as ILayoutElement;
                if (elementToSetFocus != null)
                {
                    var manager = elementToSetFocus.Root.Manager;
                    if (manager == null)
                        return;

                    IntPtr parentHwnd;
                    if (!manager.GetParentWindowHandle(out parentHwnd))
                        return;

                    if (e.HwndActivating != parentHwnd)
                        return;

                    _setFocusAsyncOperation = Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
                    {
                        try
                        {
                            SetFocusOnLastElement(elementToSetFocus);
                        }
                        finally
                        {
                            _setFocusAsyncOperation = null;
                        }
                    }), DispatcherPriority.Input);
                }
            }
        }