Posted 14 years ago
by Mick
Version: 11.1.0545
Platform: .NET 4.0
Environment: Windows Vista (32-bit)

Hello,
I believe I have reproduced the issue of the call to DocumentWindow.Activate taking a long time referenced here:
Here is my sample: For the DocumentWindow content, I use a StackPanel with 2000 TextBlocks to eliminate any 3rd party controls that may be an issue (but representing a 3rd party control like a data grid with 200 rows and 10 columns).
About the sample:
Can you reproduce this and is there something I can do?
I believe I have reproduced the issue of the call to DocumentWindow.Activate taking a long time referenced here:
Here is my sample: For the DocumentWindow content, I use a StackPanel with 2000 TextBlocks to eliminate any 3rd party controls that may be an issue (but representing a 3rd party control like a data grid with 200 rows and 10 columns).
About the sample:
- I have placed the same control in a WPF grid next to it for reference
- DocumentWindow.Activate performs on average 5-100 times worse than the standard WPF Grid (performance seems to degrade depending on what other programs are open on the system)
- Restarting the app and testing in the opposite order to minimize the pre-compilation / assembly loading mentioned above has minimal effect
- Switching between DocumentWindows still shows a speed hit (click the "Create new DocumentWindow" button multiple times and switch)
- Sometimes, when multiple WPF applications are open (like multiple instances of VS2010), the entire application is less responsive with a populated DocumentWindow as opposed to a populated System.Windows.Controls.Grid (try resizing the sample by dragging its border). This is less reproducible than the time issues - I've reproduced it on 2/4 machines that I've tested on, but the speed issue is present on all 4.
<Window
x:Class="ActivateWindow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:docking="http://schemas.actiprosoftware.com/winfx/xaml/docking"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<docking:DockSite Name="docksite">
<docking:Workspace>
<docking:TabbedMdiHost>
<docking:TabbedMdiContainer />
</docking:TabbedMdiHost>
</docking:Workspace>
</docking:DockSite>
<Grid x:Name="DockingGrid" Grid.Column="1" />
<Button Grid.Row="1" Content="Create new DocumentWindow with content" Margin="2" Click="ShowDocumentWindow" />
<Button Grid.Row="1" Grid.Column="1" Content="Create content directly" Margin="2" Click="SetGridChild" />
</Grid>
</Window>
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using ActiproSoftware.Windows.Controls.Docking;
namespace ActivateWindow
{
public partial class MainWindow : Window
{
public MainWindow() { InitializeComponent(); }
private void ShowDocumentWindow(object sender, RoutedEventArgs e)
{
MyUserControl myUserControl = new MyUserControl();
// Create a DocumentWindow and set its content
DocumentWindow documentWindow = new DocumentWindow(docksite, "window", "window", null, null);
documentWindow.Content = myUserControl;
// Time the DocumentWindow.Activate function
Stopwatch stopwatch = Stopwatch.StartNew();
documentWindow.Activate();
MessageBox.Show(stopwatch.Elapsed.ToString(), "Layout Time: DocumentWindow.Activate");
}
private void SetGridChild(object sender, RoutedEventArgs e)
{
MyUserControl myUserControl = new MyUserControl();
// Time the WPF engine layout with built in controls
Stopwatch stopwatch = Stopwatch.StartNew();
DockingGrid.Children.Clear();
DockingGrid.Children.Add(myUserControl);
MessageBox.Show(stopwatch.Elapsed.ToString(), "Layout Time: WPF standard controls");
}
}
public class MyUserControl : UserControl
{
public MyUserControl()
{
StackPanel sp = new StackPanel();
for (int i = 0; i < 2000; i++)
sp.Children.Add(new TextBlock { Text = "TextBlock " + i });
this.Content = new ScrollViewer { Content = sp };
}
}
}