3

TL;DR

It seems setting the AllowTransparency to True offsets the window up and left by 8 pixels when maximized, I need to get it back on screen.

In-depth

It looks like I am making a mistake somewhere, but am not sure why. I cannot post the entire code, but I will try to write everything relevant here.

I have my main window, which has a custom title bar. That means I had to set WindowsStyle to None and I was also using a template. Right from the start, I had problems with window being much bigger than my desktop, while maximized. It was going 8 pixels off screen on ALL SIDES. I ditched the template and tried to alter the existing window to suit my needs. By setting AllowTransparency back to false, I managed to get rid of the leakage on the sides. Problem that then occurred, is the border on top of the window, which I removed by setting the CaptionHeight of WindowChrome to 0.

Okay, the leakage is gone. But I believe my current problem is connected with what I wrote above. That is, I can't bind width and height to something, there is no appropriate property. This is what I tried from SystemParameters:

SystemParameters.FullPrimaryScreenHeight;
SystemParameters.FullPrimaryScreenWidth;
SystemParameters.MaximizedPrimaryScreenHeight;
SystemParameters.MaximizedPrimaryScreenWidth;
SystemParameters.PrimaryScreenHeight;
SystemParameters.PrimaryScreenWidth;
SystemParameters.WorkArea.Height;
SystemParameters.WorkArea.Width;
SystemParameters.VirtualScreenWidth;

The actual height required (1048) is somewhere between SystemParameters.WorkArea.Height (1040) and SystemParameters.MaximizedPrimaryScreenHeight (1056).

And the actual width required (1928) is somewhere between SystemParameters.WorkArea.Width (1920) and SystemParameters.MaximizedPrimaryScreenWidth (1936).

You can see the pattern here.

  • MaximizedPrimaryScreenWidth and MaximizedPrimaryScreenHeight are both bigger by 8 pixels from what I need
  • WorkArea.Width and WorkArea.Height are both smaller by 8 pixels from what I need
  • I had leakage on all sides before by 8 pixels

This is my window code

<Window x:Class="MyApp.MainWindow"
        ...
        WindowState="Normal" 
        ResizeMode="CanResizeWithGrip"
        MaxHeight="{Binding SystemParameters.WorkArea.Height}"
        WindowStyle="None">
    <WindowChrome.WindowChrome>
        <WindowChrome CaptionHeight="0"/>
    </WindowChrome.WindowChrome>
    ....content....
</Window>

What also doesn't work:

- Window.Padding
- Window.Margin
- Window.Top
- WindowStyle="SingleBorderWindow"

What I have but don't want

XAML:
MaxWidth="{Binding MaximumWidth}"

C#
public double MaximumWidth
{
    get
    {
        // I don't want anything hard-coded.
        // Some other (correct) parameter would be fine as well,
        // if we can't get the window on screen.
        return SystemParameters.WorkArea.Width + 8;
    }
}

Update: SingleBorderWindow

This is what happens when using WindowStyle="SingleBorderWindow".

enter image description here

So, not only is my window 8 pixels short to both my right and bottom edges (while binding to WorkArea), but you can see the actual window behind and the buttons are clickable (even where they are not visible). Really weird. It is like there are two windows, but only the one I need is not on the right location.

Adder
  • 165
  • 1
  • 14

2 Answers2

0

The actual height required (1048) is somewhere between SystemParameters.WorkArea.Height (1040) and SystemParameters.MaximizedPrimaryScreenHeight (1056).

And the actual width required (1928) is somewhere between SystemParameters.WorkArea.Width (1920) and SystemParameters.MaximizedPrimaryScreenWidth (1936).

I think you need to understand Windows Resolutions to help you solve this and

i believe 15 inches Window is 1366 X 768 in resolution Width x Height

so you using resolution higher than this will make your app bigger in size than default system resolution. Hope this help

Ogunleye Olawale
  • 306
  • 3
  • 17
  • No, resolution has nothing to do with this. Forget about those numbers, they are here as an example. Those 8 pixels is what is the problem. And it is the same in all resolutions, it is always 8 pixels too narrow and too short. – Adder Jul 03 '18 at 08:38
  • Maybe the height tricked you. My screen is 1080 pixels high, but the taskbar is taken into account here. – Adder Jul 03 '18 at 08:41
  • You using resolution from your project higher than your screen will always conflict with each other – Ogunleye Olawale Jul 03 '18 at 08:59
  • I guess I am not clear enough. My priority is to get the application back on screen. I can get the right window size, but it is not a clean solution. – Adder Jul 03 '18 at 09:08
0

Oh. If I guess well, in your code which is hidden for us, on a certain event, to maximize your window, you change it's width to SystemParameters.MaximizedPrimaryScreenWidth. Wrong. Bind to WindowState and change it to WindowState.Maximized.

Maciek Świszczowski
  • 1,155
  • 11
  • 28
  • Good guess, but no. I am maximizing by changing `WindowState` and nothing else. I do have `StateChanged` event covered, but I only change the icon for the maximize button there. – Adder Jul 04 '18 at 07:05