WPF Maximized Window bigger than screen

后端 未结 5 1510
情话喂你
情话喂你 2021-02-19 06:24

When creating a WPF window with AllowsTransparency=\"True\" WindowStyle=\"None\" and maximizing it via this.WindowState = WindowState.Maximized; the Wi

相关标签:
5条回答
  • 2021-02-19 06:57

    A couple year late to the party but just increase your this.borderthickness for the SizeChanged event like so:

    <Window x:Class="MyApp.MainWindow"
        ResizeMode="CanResize" 
        WindowStyle="SingleBorderWindow"
        SizeChanged="Window_SizeChanged">
    ....
    Code
    ....
    </Window>
    
    
    public void Window_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            if (this.WindowState == WindowState.Maximized)
            {
                this.BorderThickness = new System.Windows.Thickness(8);
            }
            else
            {
                this.BorderThickness = new System.Windows.Thickness(0);
            }
        }
    
    0 讨论(0)
  • 2021-02-19 06:58

    Unfortunately there is no good solution to this other than to make a WindowStyle="None" window without resizing, and handle everything yourself. This means your own maximize/minimize/restore buttons that set the window dimensions to fit the screen. Your own live caption area for dragging. Your own borders with the appropriate cursors. Your own double-click handler to maximize/restore. Your own routine for checking the mouse position against the height of the screen for drag-to-dock. Etc. You get the idea. It's a pain in the neck, but if you do it once at least you'll have it for all future projects. Unfortunately you will lose the "Aero" animations, but alas.

    I also want to point out one reason why this issue is very important. In at least some cases, WPF can't make full use of accelerated graphics when windows span two monitors (as they normally do any time a window is maximized). That means performance of D3DImage, as well as any Effect, suffers when the window is maximized. It was happening for me, and many of my users, which is what drew my attention to this issue.

    0 讨论(0)
  • 2021-02-19 07:04

    set this property of you window.

     MinHeight="100"
      MinWidth="100"
      Height="auto"
      Width="auto" 
    

    Hope this will work

    0 讨论(0)
  • 2021-02-19 07:08

    It seems a pretty common issue. It appears you'll have to bind your height and width to the actual height/width of the screen as stated in this StackOverflow post:

    Borderless window application takes up more space than my screen resolution.

    I hope that solves the issue you're facing.

    0 讨论(0)
  • 2021-02-19 07:13

    If you only care about the correct dimensions of your window and have no trouble with the appearance, you can wrap the contents of the window in System.Windows.Controls.Canvas like this:

    <Canvas Name="MyCanvas" Width="auto" Height="auto">
    ...
    </Canvas>
    

    Then you can use MyCanvas.ActualWidth and MyCanvas.ActualHeight to get the resolution of the current screen, with DPI settings taken into account and in device independent units. It doesn't add any margins like the maximized window itself does. It should work with multiple monitors too.

    (Canvas accepts UIElements as children, so you should be able to use it with any content.)

    0 讨论(0)
提交回复
热议问题