Borderless window application takes up more space than my screen resolution

前端 未结 8 712
忘了有多久
忘了有多久 2021-01-02 04:55

I have created a borderless application in WPF, and it works pretty good. However, when I set the WindowState to full screen, the application takes up more space than my scr

相关标签:
8条回答
  • 2021-01-02 05:08

    I needed this to work across different size displays (like most people it sounds). So I simply did this...

    <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-01-02 05:13

    I use a trigger on the window:

    <Style.Triggers>
        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self},Path=WindowState}" Value="{x:Static WindowState.Maximized}">
            <Setter Property="BorderThickness" Value="8"/>
        </DataTrigger>
    </Style.Triggers>
    

    this trigger create a Border when the windowstate is Maximized. I think it's useful.

    0 讨论(0)
  • 2021-01-02 05:16

    In Xaml set the following binding on the Window.MaxHeight:

    MaxHeight="{DynamicResource {x:Static SystemParameters.MaximizedPrimaryScreenHeightKey}}"
    

    No need for an additional utility class.

    0 讨论(0)
  • 2021-01-02 05:21

    I found this great solution

    <Window WindowStyle="None" WindowStartupLocation="CenterScreen" WindowState="Maximized"
            MaxWidth="{Binding Source={x:Static SystemParameters.WorkArea}, Path=Width}"
            MaxHeight="{Binding Source={x:Static SystemParameters.WorkArea}, Path=Height}"
        >
    ...
    </Window>
    

    But error for me still persists, windows is offset by few pixels on top and left... I tried to set Left and Top to 0 after I change window state but nothing happens.

    0 讨论(0)
  • 2021-01-02 05:22

    A newer feature of .NET has solved this problem. Leave your WindowStyle="SingleBorderWindow" or "ThreeDBorderWindow" Leave ResizeMode="CanResize", then add this to the xaml inside the

    <Window>
        <WindowChrome.WindowChrome>
            <WindowChrome GlassFrameThickness="0" CornerRadius="0" CaptionHeight="0" 
                UseAeroCaptionButtons="False" ResizeBorderThickness="7" />
        </WindowChrome.WindowChrome>
    </Window>
    

    The window will not have any of the default window pane, but will still allow resizing and will not cover the task bar when maximized.

    0 讨论(0)
  • 2021-01-02 05:24

    Try this

    Width="{Binding Source={x:Static SystemParameters.WorkArea}, Path=Width}"
    Height="{Binding Source={x:Static SystemParameters.WorkArea}, Path=Height}"
    
    0 讨论(0)
提交回复
热议问题