DocumentWindow.Activate(false) steal focus

Docking/MDI for WPF Forum

Posted 9 years ago by Roger Rong
Version: 9.2.0515
Platform: .NET 3.5
Environment: Windows Vista (32-bit)
Avatar
Hi there,

I am using the following code to create a document and expecting the window focus does not jump to the new window. But the old window loses the focus and the new document window always gets focused.

DocumentWindow dw = new DocumentWindow(dockSite, windowKey, title,
                windowImageSource, windowContent);
dw.Activate(false);
And the above issue does not occur for a tool window.

Comments (9)

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Roger,

Thanks for the note, it appears that if the Window wasn't open when calling DockingWindow.Activate(bool) then it was always focusing it. We've corrected this for the WPF Studio 2010.1 release.

In the meantime you can call DockingWindow.Open(). And if you need to ensure the tab is selected but not focused after that, you can call DockingWindow.Activate(false).


Actipro Software Support

Posted 9 years ago by Roger Rong
Avatar
Thanks for the updating.

It seems that both 'DockingWindow.Open()' and ' DockingWindow.Activate(false)' can create document window. So what is the difference between them?
Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Roger,

Open() will add the tab to the layout but will not ensure it is selected. Activate(false) will open it and ensure it is selected. Activate(true) will do what Activate(false) does but also focus it.


Actipro Software Support

Posted 9 years ago by Roger Rong
Avatar
Thanks for info.

When a document window is "selected", does it mean it is the TabbedMdiHost.PrimaryWindow?
Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Roger,

Offhand, I believe selected would mean in a tabbed MDI that it is the selected tab within a TabbedMdiContainer. But if you have more than one TabbedMdiContainer active in the layout, you could have more than one "selected" document tab in the layout, since each TabbedMdiContainer has exactly one selected tab.


Actipro Software Support

Posted 9 years ago by Roger Rong
Avatar
Got it. Thanks.
Posted 6 years ago by Roger Rong
Avatar

Hi there,

As suggested, I am using the DockingWindow.Open() to avoid stealing focus from other applications when creating a document window.

Recently some cusotmers reported they lost focus from MS Word (or other applications) when a document window is created in our product. We output the call stack in the RibbonWindow.Activated event, it seems that the ActiproSoftware.Windows.Controls.Docking.DockingWindow.Open() invokes the System.Windows.Window.Activate() method  behind sceneces. We guess that could be the reason of users losing their focuses.

Following is the call stack. Any hep appreciated.

(At moment we are using the WPF Sudio version 10.1.521.0. )

at ADSWPFHost.Views.MainView.MainView_Activated(Object sender, EventArgs e) in D:\Working\ADSWPFHost\ADSWPFHost\Views\MainView.xaml.cs:line 44
at ActiproSoftware.Windows.Controls.Ribbon.RibbonWindow.OnActivated(EventArgs e)
at System.Windows.Window.WmActivate(IntPtr wParam)
at System.Windows.Window.WindowFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.PublicHooksFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.SetForegroundWindow(HandleRef hWnd)
at MS.Win32.UnsafeNativeMethods.SetForegroundWindow(HandleRef hWnd)
at System.Windows.Window.Activate()
at ActiproSoftware.Windows.Controls.Docking.DockSite.b(DockingWindow A_0, Boolean A_1)
at ActiproSoftware.Windows.Controls.Docking.DockSite.b(DockingWindow A_0)
at ActiproSoftware.Windows.Controls.Docking.DockSite.a(DockingWindow A_0, Boolean A_1, Boolean A_2)
at ActiproSoftware.Windows.Controls.Docking.DockingWindow.Open()
at ADSWPFHost.ViewModels.MainViewModel.CreateDocumentWindow(UIElement windowContent, String windowKey, ImageSource windowImageSource, String title, Boolean isFocus, Boolean canClose) in D:\Working\ADSWPFHost\ADSWPFHost\ViewModels\MainViewModel.cs:line 419
at ADSWPFHost.Models.HostServer.CreateDocumentWindow(String key, UIElement windowContent, IServiceProvider windowAssoicatedData, String text, ImageSource windowIamageSource, Boolean canClose, Boolean isFocus) in D:\Working\ADSWPFHost\ADSWPFHost\Models\HostServer.cs:line 148

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Roger,

I believe this was something we changed in a later version (in early 2012) so it doesn't Activate the Window when you call Open().


Actipro Software Support

Posted 6 years ago by Roger Rong
Avatar

Thanks. We have tried the version 2013.1.0583 and it does fix the problem.

The latest build of this product (v2019.1 build 0681) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.