-better late then never-
From your code fragment I am assuming that you created your own custom window. First of all: if you use AllowsTransparency your window will not be able to display any old style controls (for example: web browser). Unfortunately, without this, the window will not snap to screen.
Putting that aside, what I did to maximize correctly is to
1. Add a maximize/restore behavior to the max/restore window button. This behavior simply triggers maximize/restore command.
2. In my XAML the entire window logic is inside a border. Like this...
<Border x:Name="PART_WindowBorder">
</Border>
3. My maximize/restore command looks like this.
public void Execute(object parameter)
{
var window = parameter as Window;
if (window != null)
{
Border border = window.Template.FindName("PART_WindowBorder", window) as Border;
if (window.WindowState == WindowState.Maximized)
{
border.Margin = new Thickness(0);
window.WindowState = WindowState.Normal;
}
else
{
border.Margin = new Thickness(6);
window.WindowState = WindowState.Maximized;
}
}
}
So you simply increase the margin to 6 when maximized (offset is 7, my border is 1). In here, you can also check for correct window version and read margin using GetSystemMetrics.
Regards,
Tomaz