Index: Core/Common/src/Core.Common.Gui/Forms/NativeMethods.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -r19cdffefedec35986230b2ddc69d0ea524d29cec --- Core/Common/src/Core.Common.Gui/Forms/NativeMethods.cs (.../NativeMethods.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Common/src/Core.Common.Gui/Forms/NativeMethods.cs (.../NativeMethods.cs) (revision 19cdffefedec35986230b2ddc69d0ea524d29cec) @@ -64,25 +64,5 @@ /// [DllImport("uxtheme.dll", CharSet = CharSet.Unicode)] public static extern int SetWindowTheme(IntPtr hWnd, string textSubAppName, string textSubIdList); - - /// - /// Call this method on a view if you want to trigger data binding. For example - /// when switching between views, closing a view or when performing a save. - /// - /// Control to unfocus / trigger validation. - public static void UnfocusActiveControl(IContainerControl containerControl) - { - if (containerControl == null) - { - return; - } - - while (containerControl.ActiveControl is IContainerControl) - { - containerControl = (IContainerControl) containerControl.ActiveControl; - } - - containerControl.ActiveControl = null; // Unfocus the current control (to force binding to happen) - } } } \ No newline at end of file Index: Core/Common/src/Core.Common.Gui/Forms/ViewHost/AvalonDockViewHost.xaml.cs =================================================================== diff -u -rd8f94e15074f52f8c933b1b67fbc619547760ab7 -r19cdffefedec35986230b2ddc69d0ea524d29cec --- Core/Common/src/Core.Common.Gui/Forms/ViewHost/AvalonDockViewHost.xaml.cs (.../AvalonDockViewHost.xaml.cs) (revision d8f94e15074f52f8c933b1b67fbc619547760ab7) +++ Core/Common/src/Core.Common.Gui/Forms/ViewHost/AvalonDockViewHost.xaml.cs (.../AvalonDockViewHost.xaml.cs) (revision 19cdffefedec35986230b2ddc69d0ea524d29cec) @@ -267,14 +267,9 @@ private void OnActiveContentChanged(object sender, EventArgs eventArgs) { - // Note: Raise (un)focus related events manually as changing focus from one WindowsFormsHost to another does not raise them - // (see https://msdn.microsoft.com/en-us/library/ms751797(v=vs.100).aspx#Windows_Presentation_Foundation_Application_Hosting). - // While doing so: - // - prevent unfocus actions when removing views programmatically (not necessary and might interfere with AvalonDock's active content change behavior); - // - prevent circular active content changes (which explains the code structure below). - if (activeView != null && !removingProgrammatically) + if (!removingProgrammatically) { - PerformWithoutChangingActiveContent(() => NativeMethods.UnfocusActiveControl(activeView as IContainerControl)); + UnfocusActiveView(); } activeView = GetView(DockingManager.ActiveContent); @@ -291,6 +286,32 @@ OnActiveViewChanged(); } + /// + /// Performs unfocus action for the current active view. + /// + /// + /// Raising unfocus events manually is necessary when changing focus from one WindowsFormsHost to another (also see + /// https://msdn.microsoft.com/en-us/library/ms751797(v=vs.100).aspx#Windows_Presentation_Foundation_Application_Hosting). + /// + private void UnfocusActiveView() + { + var containerControl = activeView as IContainerControl; + if (containerControl == null) + { + return; + } + + PerformWithoutChangingActiveContent(() => + { + while (containerControl.ActiveControl is IContainerControl) + { + containerControl = (IContainerControl) containerControl.ActiveControl; + } + + containerControl.ActiveControl = null; + }); + } + private void OnLayoutDocumentClosed(object sender, EventArgs e) { var layoutDocument = (LayoutDocument) sender;