I made a WPF Application, with a window a Grid and a button. In the window SizeChanged event I scaleTransform my Grid to maximize it’s size but keeping the aspect ratio.
When ever I move the mouse over the button, the hottrack occurs as you would expect, but the mouse stalls for less than half a second, not a huge problem but it seems something isn’t right.
EDIT I suppose I never actually asked a question. What I want to know is. is this normal behavior, or is there something wrong with how I am doing this.
//Store the initial size of the Grid
double GridStartWidth;
double GridStartHeight;
public MainWindow()
{
InitializeComponent();
//Get the values for the initial size of Grid
GridStartWidth = MainGrid.Width;
GridStartHeight = MainGrid.Height;
}
private void myMainWindow_SizeChanged(object sender, SizeChangedEventArgs e)
{
double min = Math.Min(this.Height / GridStartHeight, this.Width / GridStartWidth);
Transform tr = new ScaleTransform(min, min, .5, .5);
MainGrid.LayoutTransform = tr;
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
Not sure if you need the Xaml but here it is
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
Name="myMainWindow"
Width="1280" Height="1024" SizeChanged="myMainWindow_SizeChanged" AllowsTransparency="True" Background="#4FFFFFFF" WindowStyle="None" WindowState="Maximized">
<Grid Name="MainGrid" Background="#FF8DC78D" Width="800" Height="600">
<Button Content="Exit" Height="23" HorizontalAlignment="Left" Margin="13,12,0,0" Name="ExitButton" VerticalAlignment="Top" Width="75" Click="button1_Click" />
</Grid>
EDIT #2 I just tried to duplicate this issue starting from scratch, and testing it step by step as I added features. The problem occurs when I set the Window State as Maximized.
EDIT #3 Another Test I removed the Allow Transparency property, and set the background to a solid color, and it works fine. So the Problem has to do with Maximized window with a transparent background. Does this make sense?
Updating the mouse pointer on the screen in Windows has very high priority and mouse jitter or stutter is a result of driver problems or serious performance problems.
WPF is available on Windows XP but hardware acceleration is not always available leading to performance problems. In particular there is a problem that affects transparent windows (which you use).
Dwayne Need from Microsoft has a blog post about Transparent Windows in WPF:
Your experience may be a result of not having the hot fix on your computer (but it is included in SP3), or a result of WPF having to switch to software rendering for your particular application.