WPF: remove header / control block

I just switched from WinForms to wpf, and in WinForms deleting the entire header field is very simple, just set title = "" and ControlBox = false.

Now there are many suggestions on how to do this using wpf, and they all use their own Win32 calls. Although they remove the control unit, they still leave a thicker border at the top.

This is how I want it to look.

I am sure that this is possible using some kind of native challenge, but how?

+5
source share
3 answers

Ok try this

WindowStyle="none"

like this:

<Window x:Class="Test.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow"  WindowStyle="None"
    MinHeight="350" MaxHeight="350" MinWidth="525" MaxWidth="525">
<Grid>

</Grid>
</Window>

Edit:

, ( Min- MaxHeight/Width )

+8

. Max-/minim, ResizeMode

<Window x:Class="MyWpfApplication.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="" Height="350" Width="525" ResizeMode="NoResize">
    <Grid>

    </Grid>
</Window>

"", ( )

private const int GWL_STYLE = -16;
private const int WS_SYSMENU = 0x80000;
[DllImport("user32.dll", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

public MainWindow()
{
    SourceInitialized += Window_SourceInitialized;
}

void Window_SourceInitialized(object sender, EventArgs e)
{
    var hwnd = new WindowInteropHelper(this).Handle;
    SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);
}
+5

Set WindowStyle = none

0
source

All Articles