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"
.
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.