protected override void FocusContent() { WpfWorkbench.FocusDebug("{0}.FocusContent() IsActiveContent={1} IsKeyboardFocusWithin={2} Keyboard.FocusedElement={3}", Title, IsActiveContent, IsKeyboardFocusWithin, Keyboard.FocusedElement); if (!(IsActiveContent && !IsKeyboardFocusWithin)) { return; } IInputElement activeChild = CustomFocusManager.GetFocusedChild(this); WpfWorkbench.FocusDebug("{0}.FocusContent() - Will move focus (activeChild={1})", this.Title, activeChild); // use lambda for fetching the active child - this is necessary because the ActiveViewContent might change until the background // action is called AvalonWorkbenchWindow.SetFocus(this, () => activeChild ?? (ActiveViewContent != null ? ActiveViewContent.InitiallyFocusedControl as IInputElement : null)); }
internal static void SetFocus(ManagedContent m, Func <IInputElement> activeChildFunc, bool forceSetFocus = false) { m.Dispatcher.BeginInvoke( DispatcherPriority.Background, new Action( delegate { // ensure that condition for FocusContent() is still fulfilled // (necessary to avoid focus switching loops when changing layouts) if (!forceSetFocus && !(m.IsActiveContent && !m.IsKeyboardFocusWithin)) { WpfWorkbench.FocusDebug("{0} - not moving focus (IsActiveContent={1}, IsKeyboardFocusWithin={2})", m.Title, m.IsActiveContent, m.IsKeyboardFocusWithin); return; } IInputElement activeChild = activeChildFunc(); WpfWorkbench.FocusDebug("{0} - moving focus to: {1}", m.Title, activeChild != null ? activeChild.ToString() : "<null>"); if (activeChild != null) { Keyboard.Focus(activeChild); } })); }
void dockingManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == "ActiveContent") { WpfWorkbench.FocusDebug("AvalonDock: ActiveContent changed to {0}", WpfWorkbench.GetElementName(dockingManager.ActiveContent)); if (ActiveContentChanged != null) { ActiveContentChanged(this, e); } CommandManager.InvalidateRequerySuggested(); } else if (e.PropertyName == "ActiveDocument") { WpfWorkbench.FocusDebug("AvalonDock: ActiveDocument changed to {0}", WpfWorkbench.GetElementName(dockingManager.ActiveDocument)); if (ActiveWorkbenchWindowChanged != null) { ActiveWorkbenchWindowChanged(this, e); } CommandManager.InvalidateRequerySuggested(); } }