WindowActivated doesn't always fire

Docking/MDI for WPF Forum

Posted 15 years ago by Jon von Gillern
Version: 9.1.0503
Platform: .NET 3.5
Environment: Windows Vista (32-bit)
Avatar
This took a while to figure what was causing this, but I finally got it:

If you have a TabbedMdiContainer where all of the documents have 'CanDrag="False"' the WindowActivate Event will not fire if a ToolWindow has focus. Once you give focus to the contents of the document window you can change doc windows back and forth and the event will fire. But as soon as you click another ToolWindow, the window activated event will not fire until you click on the contents of the document window.

Here is sample code:

<DockPanel LastChildFill="True">
        <docking:DockSite x:Name="MyWholeDockSite">
            <docking:SplitContainer Orientation="Horizontal" >
                <docking:ToolWindowContainer >
                    <docking:ToolWindow Title="Tool Window">
                        <StackPanel>
                            <TextBox Text="Tool Window TextBox" />
                        </StackPanel>
                    </docking:ToolWindow>
                </docking:ToolWindowContainer>
                    <!-- Documents -->
                    <docking:Workspace>
                        <docking:DockSite x:Name="RuleDockSite" 
                                      WindowActivated="RuleDockSite_WindowActivated"
                                      >
                            <docking:Workspace>
                                <docking:TabbedMdiHost IsCloseButtonOnTab="True" >
                                    <docking:TabbedMdiContainer>
                                        <docking:DocumentWindow Title="Doc1" CanDrag="False">
                                            <TextBox Text="Doc1" />
                                        </docking:DocumentWindow>
                                        <docking:DocumentWindow Title="Doc2" CanDrag="False">
                                            <TextBox Text="Doc2" />
                                        </docking:DocumentWindow>
                                    </docking:TabbedMdiContainer>
                                </docking:TabbedMdiHost>
                            </docking:Workspace>
                        </docking:DockSite>
                    </docking:Workspace>
            </docking:SplitContainer> 
        </docking:DockSite>
    </DockPanel>

private void RuleDockSite_WindowActivated(object sender, ActiproSoftware.Windows.Controls.Docking.DockingWindowEventArgs e)
{
    Console.WriteLine("Activated " + e.Window.Title);
}
If you set the CanDrag attribute to true, everything works as expected - the WindowsActivated Event fires regardless of what previously had focus.

[Modified at 08/16/2009 10:11 PM]

Comments (1)

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

Note that I'm testing with build 504 (hopefully to be released this week) which has some tweaks to the WindowActivated event, and therefore may yield some different results than what you see.

When I run your code (both with and without CanDrag set) I see the same result. I only see the document windows raise WindowActivated events, even when the tool window gets focus. This is accurate because you put the event handler on the nested DockSite, which doesn't know about the tool window in the root DockSite, it only shows events for the document windows.


Actipro Software Support

The latest build of this product (v24.1.1) 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.