Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot fully programatically maximize window. #1823

Closed
pingu2k4 opened this issue Feb 27, 2015 · 26 comments
Closed

Cannot fully programatically maximize window. #1823

pingu2k4 opened this issue Feb 27, 2015 · 26 comments
Assignees
Labels
Milestone

Comments

@pingu2k4
Copy link

Hi,

Having this live of code called: this.WindowState = System.Windows.WindowState.Maximized;

does change the size of the window, however there are borders all around the window, where the window isn't touching the edge of the screen or the taskbar. Here is my opening window tag:

    <Controls:MetroWindow x:Name="GameWindow" x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
                      ShowMinButton="False"
                      ShowMaxRestoreButton="False"
                      ResizeMode="NoResize"
                      SaveWindowPosition="True"
        Title="MainWindow" Height="350" Width="525" GlowBrush="#FF07908E" Background="#FF252525"
                      WindowState="Maximized"
                      IgnoreTaskbarOnMaximize="True">

Effectively, I want to come out of fullscreen as it is set to when it launches, and have it take up all the screen but not cover the taskbar... Which it does apart from it leaves this strange gap around....

2

@punker76
Copy link
Member

@pingu2k4 which version?

@pingu2k4
Copy link
Author

Apologies. Version 1.1.1.0.

As can probably be seen by the simplicity of the program so far I am kind of new to this framework, but I can't find how to do this anywhere I search online, and I'm sure that it should work correctly with what I have...

@pingu2k4
Copy link
Author

Just an update - I am now at home where I have 2 monitors and not just 1.
I get the exact same result here with the same project. however, I created a new project with mahapps.metro and a simple button. I used the same line of code to maximise, and on the new project it worked fine...

@pingu2k4
Copy link
Author

OK, so I have found out where the problem lies. I had set
ResizeMode="NoResize"
And this is where the problem lies. I don't know whether it is expected behaviour to act as it does when this is set to noresize, but I can get this working properly with the following:

this.ResizeMode = System.Windows.ResizeMode.CanResize;
this.IgnoreTaskbarOnMaximize = !this.IgnoreTaskbarOnMaximize;
this.WindowState = System.Windows.WindowState.Maximized;
this.ResizeMode = System.Windows.ResizeMode.NoResize;

I am happy with using this whether I should have to or not really... I'll just keep this open for time being in case you want to do anything with this still. :) Feel free to close though.

@punker76
Copy link
Member

@pingu2k4 this is fixed with 39a7e05

@davidefu
Copy link
Contributor

hi everyone,
i think this issue is still open in version 1.2.4 (from nuget).
please check the attached project
thanks
Davide
mahappsdemo.zip

@punker76 punker76 reopened this Mar 18, 2016
@punker76 punker76 added this to the 1.3.0 milestone Mar 18, 2016
@punker76 punker76 self-assigned this Mar 18, 2016
@punker76 punker76 modified the milestones: 2.0.0, 1.3.0 Mar 20, 2016
punker76 added a commit that referenced this issue Mar 25, 2016
@punker76
Copy link
Member

@davidefu Should be fixed now in latest pre-release. As a workaround (with latest stable 1.2.4) set the ResizeMode in loaded event

this.Loaded += (sender, args) => this.ResizeMode = ResizeMode.NoResize;

@davidefu
Copy link
Contributor

thanks

@davidefu
Copy link
Contributor

hi,
strange issue in the last alpha version 1.3.0.134
if i create a window with style: none, resizemode: noresize, state: Maximized the window ignore the window taskbar and overlap.
but there is a way to resize the window with the shortcut windows + down arrow
if i force in the windowstatechanged event the maximized state, the window is not fully maximized.

By the way wich is the correct way to create a full (with no taskbar overlapping) non resizable window?
please check the attached project

immagine
mahappsalphaissue.zip

Thanks

@punker76
Copy link
Member

@davidefu Is this a normal running Win10? or is it inside a VM?

You can use IsWindowDraggable="False" instead doing this

        void MainWindow_StateChanged(object sender, EventArgs e)
        {
            if (this.WindowState != System.Windows.WindowState.Maximized)
            {
                this.WindowState = System.Windows.WindowState.Maximized;
            }
        }

Here is the working xaml (without any code behind stuff) that works here on my win 7 prof 64 bit machine

<Controls:MetroWindow x:Class="WpfApplication2.MainWindow"
                      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
                      Title="MainWindow"
                      Width="525"
                      Height="350"
                      ResizeMode="NoResize"
                      IsMinButtonEnabled="False"
                      IsWindowDraggable="False"
                      Topmost="True"
                      WindowState="Maximized"
                      WindowStyle="None">
  <Grid Background="Red">
    <TextBlock><Run Text="1.3.0.134" /></TextBlock>
  </Grid>
</Controls:MetroWindow>

@punker76
Copy link
Member

@davidefu by the way, the shortcut windows + down arrow is normal behavior in win 10, just tested it out with normal window instead MetroWindow.

And, I take your sample with my changes and run it inside VMWare with Win10... and it works :-(

2016-04-25_21h03_06

2016-04-25_21h03_22

@davidefu
Copy link
Contributor

hi,
i'm on a normal windows 10 on a surface pro 4 (so with 175% or 200% of zoom)
i tried with your code, but i don't understand how to make the window maximized without overlap the taskbar.
so is there a way to override the behavior of the windows + down arrow?
if i force (with the code you saw on statechanged event) the maximized state the window appears with the border around it.
same issue if i set the maximized state on windows loaded insted of one the xaml

thanks
davide

@punker76
Copy link
Member

i'm on a normal windows 10 on a surface pro 4 (so with 175% or 200% of zoom)

ok, i'll try on my VM and PC this setting with Win 10, but not with a surface, that's not my price class :-)

i tried with your code, but i don't understand how to make the window maximized without overlap the taskbar.

taskbar issue is (should be) fixed with MahApps.Metro 1.3.0-ALPHA137

so is there a way to override the behavior of the windows + down arrow?

i don't know, maybe you can prevent the keys in preview key events

if i force (with the code you saw on statechanged event) the maximized state the window appears with the border around it.

setting the maximized state in the state event is not a good idea

same issue if i set the maximized state on windows loaded insted of one the xaml

yeah maybe this is an issue with your settings of the dpi zoom...

@davidefu
Copy link
Contributor

great. l'll be happy to test the next release

@punker76
Copy link
Member

@davidefu by the way ResizeMode="NoResize" and WindowState="Maximized" are not good friends! doesn't working with normal windows too!

@davidefu
Copy link
Contributor

@punker76 now in the alpha 137 resizemode="NoResize" and WindowState="Maximized" seems to be good friends also with high dpi monitor. Thanks a lot for the support.
Extra chapter:
with this code i was able to override the windows + down arrow

`private const int WM_SYSCOMMAND = 0x0112;
private const int SC_RESTORE = 0xF120;

    protected override void OnSourceInitialized(EventArgs e)
    {
        base.OnSourceInitialized(e);
        HwndSource source = PresentationSource.FromVisual(this) as HwndSource;
        source.AddHook(WndProc);
    }

    private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
    {
        if (msg == WM_SYSCOMMAND && wParam.ToInt32() == SC_RESTORE)
        {
            Debug.WriteLine(msg);
            handled = true;
        }

        return IntPtr.Zero;
    }`

extra detail here https://msdn.microsoft.com/en-us/library/windows/desktop/ms646360(v=vs.85).aspx

@davidefu
Copy link
Contributor

davidefu commented May 4, 2016

@punker76
hi, i've found another really strange issue.
it's happening only with a .NET 4.0 apps (not in .NET 4.5)
and it's not reproducible with the visual studio debugger attacched, so only running from the bin folder directly
you can see that the window is not fully maximized
image
i've tested it on windows 10 with 100% of zoom and 175% of zoom, save behavior
please find the attacched project
WpfApplication2.zip

@davidefu
Copy link
Contributor

davidefu commented May 4, 2016

@punker76
Copy link
Member

punker76 commented May 4, 2016

@davidefu please try again with 1.3.0.145, thx!!!

@punker76
Copy link
Member

punker76 commented May 4, 2016

@davidefu any news?

@davidefu
Copy link
Contributor

davidefu commented May 4, 2016

@punker76 hi, the test app attacched is working fine.
tomorrow morning i'll make a more deep test and on a different machine.

@davidefu
Copy link
Contributor

davidefu commented May 5, 2016

i notice a strange issue.
with noresize in xaml i can still resize with win+arrow
this is not possible if i set noresize in loaded event but the window overlap the taskbar

@punker76
Copy link
Member

punker76 commented May 5, 2016

I think we can't fix this in a good way, NoResize and maximized window is
always a bad combination ( also without MahApps ). And I don't get your
issue with the overlapping taskbar. resizing with win+arrow should be
possible, so the window can be moved to another monitors without the sizing
bug.
Am 05.05.2016 9:10 vorm. schrieb "davidefu" notifications@github.com:

i notice a strange issue.
with noresize in xaml i can still resize with win+arrow
this is not possible if i set noresize in loaded event but the window
overlap the taskbar


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#1823 (comment)

@davidefu
Copy link
Contributor

davidefu commented May 5, 2016

the win+arrow was not possible in previous alpha (except for win+down)

the window overlap the taskbar only if i the the resize mode in loaded event and nothing in the xaml

@davidefu
Copy link
Contributor

davidefu commented May 5, 2016

the alpha141 has good bahavior except for the runtime issue regarding the borderthickness

@davidefu
Copy link
Contributor

davidefu commented May 5, 2016

maybe a typo but in BorderlessWindowBehavior.cs at line 84
if you change the line to this.AssociatedObject.ResizeMode = ResizeMode.NoResize;
the behavior seems to be correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants