45

Is it possible to remove the white strip on top of WPF window with Window Style=None. XAML and Window is shown in the screenshot:

enter image description here

Joginder S Nahil
  • 791
  • 1
  • 6
  • 17
  • I can't see anything in the visual tree that's causing this but I can reproduce it on Windows 10. I wonder whether that happens in prior Windows versions, too. Maybe it's a bug introduced due to differences in how the window layout and borders are handled. – Joey Apr 14 '16 at 18:37
  • Possible duplicate of [How to create custom window chrome in wpf?](http://stackoverflow.com/questions/6792275/how-to-create-custom-window-chrome-in-wpf) – devuxer Apr 14 '16 at 18:54

4 Answers4

47

What you are seeing in white is the re-size border. You can remove that and still make the window resizable by setting ResizeMode="CanResizeWithGrip" AllowsTransparency="True"

If you dont want to resize at all then do this - ResizeMode="NoResize", again you wont see the border but you cant resize.

<Window x:Class="HandsOnSolution.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" Background="Green" WindowStyle="None" ResizeMode="CanResizeWithGrip" AllowsTransparency="True">
    <Grid>
    </Grid>
</Window>

Edit

Good point by @devuxer, if you are interested in dragging you can add this piece of code to the window mouse down event

<Window MouseLeftButtonDown="Window_MouseLeftButtonDown"/>

//code behind
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    DragMove();
}
Carbine
  • 7,849
  • 4
  • 30
  • 54
  • Trying this out, it seems like you can't actually move the window, and you can only resize it from the lower right corner, so it cripples the resize capability quite a bit. Perhaps this is what the OP needs, though. – devuxer Apr 14 '16 at 18:46
  • 4
    I am sorry that I forgot to mention that I cannot use AllowsTransparency="True" as my WPF window renders Windows Form Controls. Windows Forms hosted on a WPF Window do not show up (see other threads) . – Joginder S Nahil Apr 14 '16 at 19:37
23

I had been hunting for a solution for a couple of days now, in simple words this link held the answer to my queries

though the code snippet that did the magic was:

<Setter Property="WindowChrome.WindowChrome">
    <Setter.Value>
        <WindowChrome CaptionHeight="0"
            CornerRadius="2"
            GlassFrameThickness="0"
            NonClientFrameEdges="None"
            ResizeBorderThickness="3"/>
    </Setter.Value>
</Setter>

I just added the above property setter to the custom Window Style.

Hope that helped :)

Yashash Gaurav
  • 581
  • 5
  • 9
  • This option works wonders. Just setting the caption height causes painting issues where you can see the caption appear while resizing. This combination works flawlessly currently and you still get full resize capabilities. – TyCobb Apr 08 '21 at 04:06
19

A much simplified code, acting on only one property:

<WindowChrome.WindowChrome>
    <WindowChrome CaptionHeight="0"/>
</WindowChrome.WindowChrome>
Yasser Elarabi
  • 205
  • 2
  • 6
  • 2
    This is the right solution, because we don't want to loose window default shadow effect, which is lost when `AllowsTransparency=True` is applied. Thanks! – Starwave Jan 29 '21 at 20:42
  • This solution uses less code than other solutions and creates the desired result without side effects. – anders-hou May 04 '21 at 20:52
  • Excellent. This still allows the shadow effect. In case you are not a dedicated WPF programmer, here is how you can set up a WindowChrome in a style: https://learn.microsoft.com/en-us/answers/questions/435201/wpf-xaml-custom-window-style-not-working – Battle Jul 12 '23 at 07:06
8

I added this piece of code:

<WindowChrome.WindowChrome>
    <WindowChrome GlassFrameThickness="0,0,0,1" CornerRadius="0" />
</WindowChrome.WindowChrome>

inside <Window> paste here <Window/> and it helped :)

brooksrelyt
  • 3,925
  • 5
  • 31
  • 54
Mateusz Piwowarski
  • 559
  • 1
  • 6
  • 15