Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AllowTransparency makes maximized overscan

I'm currently making a media player using WPF and have come across a problem.

I want the layout to have no regular windows borders and a dropshadow. I have done this by setting WindowStyle=none and AllowTransparency=true. This all works very well, as long as I do not want to use it in fullscreen. As soon as i try to set WindowState to maximized, it overscans like crazy (it cuts off all the edges). This is apparently caused by the AllowTransparency=true part. If I set this back to false, the maximized part works as intended. Unfortunately I cannot set the AllowTransparency once the application is started. I can somewhat compensate this by using a border and adjusting the margin of that, but it doesn't really look right and I am not sure it will work on different resolutions.

So to sum up:

  • Is it possible to make the WindowState maximized work like normal with AllowTransparency=true?
  • Or is there another way to make a window not have the normal windows border without setting AllowTransparency=true
  • Or is there a better way to make an application go fullscreen?

Does anyone have a solution or an idea to accomplish this?

like image 713
andidegn Avatar asked Sep 30 '22 03:09

andidegn


2 Answers

You posted the answer on the MSDN forum, but not here, so here it is;

The solution is to set the ResizeMode=NoResize when going to fullscreen. It seems that the AllowTransparency=True still has the regular border from the window, but just hides it, so when you maximize it tries to compensate for that border. But if you change ResizeMode, the border goes away.

https://social.msdn.microsoft.com/Forums/vstudio/en-US/0b938537-c048-4122-8a2f-29d04d21f2df/allowtransparency-in-fullscreen?forum=wpf

like image 51
Julius Avatar answered Oct 08 '22 16:10

Julius


My solution works for :

AllowsTransparency="True"

WindowStyle="None"

You cannot set maximize, because it goes full screen.

if (window.Tag == null){

    window.Tag = window.Width + ";" + window.Height + ";" + window.Left + ";" +
                 window.Top;
    window.Width = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
    window.Height = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
    window.Left = 0;
    window.Top = 0;
    window.WindowState = WindowState.Normal;

} else {

    List<int> sizes = new List<int>(window.Tag.ToString().Split(';').Select(int.Parse));
    window.Width = sizes[0];
    window.Height = sizes[1];
    window.Left = sizes[2];
    window.Top = sizes[3];
    window.Tag = null;
}
like image 31
Marek Schwarz Avatar answered Oct 08 '22 16:10

Marek Schwarz