tags:

views:

19

answers:

1

Hi,

I'm currently writing a program in c# wpf with a custom window. So because there has to be a custom maximizing state I want to get the height and width of the screen without the taskbar. the systemparamters.workarea property seemed to be the way to go, however the values that it has given me are wrong. Furthermore setting this as the new Maxheight and Maxwidth sets some sort of margin so that there is a small gap at the right and at the bottom of my app even though I explicitly state this.left = 0 and this.left = 0.

Has anybody got experience with this?

Update: requested code (this is run when user clicks maximize button (essentially a switch between maximize and normal)) Also there are no margins or max heights/widths in my designer window, everything is set to auto.

    private void MaxThis(object sender, System.Windows.RoutedEventArgs e)
    { if (WindowState == WindowState.Maximized){
        WindowState = WindowState.Normal;
        }

    else {
        this.MaxWidth = SystemParameters.WorkArea.Width;
        this.MaxHeight = SystemParameters.WorkArea.Height;       
        this.WindowState = WindowState.Maximized;

    this.Top = 0;
    this.Left = 0;
    }
    }

Update: I made a new blank WPF app in Blend, added a button and linked this code to it. Same margin at the right and bottom...

+1  A: 

The extra border and spacing you're seeing is the resizing frame. The simplest way to get rid of it is to set

ResizeMode = ResizeMode.NoResize;
John Bowen
Thanks! So I ever should ever want a resizegrip I'd make a custom one?
internetmw
Yes, that will give you more control over the sizing and placement. If you want to allow resizing from the maximized state you can change the ControlTemplate for the Window itself to add your own grip that doesn't require the extra spacing.
John Bowen