Posted 15 years ago
by Andy Ver Murlen
I have just discovered that the WindowOpened event is firing twice. Consider the following code.
With the following code behind.
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]
<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>
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();
}
}
}
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]