WindowOpened Event Fires Twice

Docking/MDI for WPF Forum

Posted 10 years ago by Andy Ver Murlen
Avatar
I have just discovered that the WindowOpened event is firing twice. Consider the following code.

<ribbon:RibbonWindow 
    x:Class="TestApp.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ribbon="http://schemas.actiprosoftware.com/winfx/xaml/ribbon"
    xmlns:themes="http://schemas.actiprosoftware.com/winfx/xaml/themes"
    xmlns:docking="clr-namespace:ActiproSoftware.Windows.Controls.Docking;assembly=ActiproSoftware.Docking.Wpf351"
    Title="Window1" 
    Height="300" 
    Width="300"
    themes:ThemeManager.Theme="LunaHomestead"
    >
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Button Content="Add Window" Click="Button_Click" />
        <docking:DockSite x:Name="uxDockSite_DockSite" Grid.Row="1" WindowOpened="uxDockSite_DockSite_WindowOpened">
            <docking:Workspace>
                <docking:TabbedMdiHost>
                    <docking:TabbedMdiContainer>
                        <docking:DocumentWindow Title="Hello World" />
                    </docking:TabbedMdiContainer>
                </docking:TabbedMdiHost>
            </docking:Workspace>
        </docking:DockSite>
    </Grid>
</ribbon:RibbonWindow>
With the following code behind.

using System;
using System.Windows;
using ActiproSoftware.Windows.Controls.Docking;

namespace TestApp
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void uxDockSite_DockSite_WindowOpened(object sender, ActiproSoftware.Windows.Controls.Docking.DockingWindowEventArgs e)
        {
            Console.WriteLine("Window Opened");
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            DocumentWindow window = new DocumentWindow(uxDockSite_DockSite) {Title = "Another Window"};
            window.Activate();
        }
    }
}
When this code is run, and the button is clicked to add a new window to the dock site, you will notice that "Window Opened" is output twice in the console.

This is not a huge deal here, however in the project that I am working on, I have a fairly expensive process that gets run when a new window is opened. Running it twice for one window is not a good thing.

Thanks,
Andy

[Modified at 06/23/2010 10:29 AM]

[Modified at 06/23/2010 10:30 AM]

Comments (2)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Andy,

Sorry for the late response. You are correct, and we've fixed this for the next maintenance release due out very soon.


Actipro Software Support

Posted 10 years ago by Andy Ver Murlen
Avatar
Fix confirmed, thank you.
The latest build of this product (v2020.1.1) was released 14 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.