51

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

2
  • 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. Commented Apr 14, 2016 at 18:37
  • Possible duplicate of How to create custom window chrome in wpf? Commented Apr 14, 2016 at 18:54

7 Answers 7

48

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(); } 
Sign up to request clarification or add additional context in comments.

2 Comments

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.
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) .
27

A much simplified code, acting on only one property:

<WindowChrome.WindowChrome> <WindowChrome CaptionHeight="0"/> </WindowChrome.WindowChrome> 

3 Comments

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!
This solution uses less code than other solutions and creates the desired result without side effects.
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: learn.microsoft.com/en-us/answers/questions/435201/…
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 :)

1 Comment

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.
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 :)

Comments

0

This is my workaround for this problem. It works well on windows 10, I haven't tested it on other systems yet.

As previous authors have pointed out, using WindowChrome fixes the top bar problem. However, it introduces other problems instead (I will explain and provide a fix for that below). This is the code for WindowChrome that I added to my MainWindow.xaml, but feel free to experiment:

<WindowChrome.WindowChrome> <WindowChrome CaptionHeight="0" CornerRadius="3" GlassFrameThickness="0" NonClientFrameEdges="None" ResizeBorderThickness="6" UseAeroCaptionButtons="False" /> </WindowChrome.WindowChrome> 

With WindowChrome the new problem is now maximizing the window.

Since WindowStyle="None" removes the title bar, I'm assuming that you (like me) have made some custom buttons for minimizing, maximizing, and closing the program. For maximization it is natural to use this.WindowState = System.Windows.WindowState.Maximized; (assuming this refers to the main window). But if you do it like this, the maximized window is now cropped by extending it outside the screen, and also to cover the task bar (above or below depending on different factors). So basically it's all very ugly. Don't do like this!

My solution was to adapt a brilliant piece of code—adapted and shared by Alexander Yashyn, originally from Mike Weinhardt—that you can find here: https://stackoverflow.com/a/67228878/5163713

This code manually maximizes the window according to the specific screen the program is currently on, and it seems to work really well. The only slight problem I found was that when you return from a maximized state the window is always in the top left corner of the screen. I will, however, leave it to you to save the window's last position and return it there. Happy coding!

PS. I am disappointed with Microsoft that just decided to label the issue as 'resolved', in 2022, without actually fixing the underlying problem with the top border.

Comments

0

You can use this style to do it

<Style x:Key="ChromeWindow" TargetType="Window"> <Setter Property="WindowChrome.WindowChrome"> <Setter.Value> <WindowChrome CaptionHeight="30" GlassFrameThickness="3" NonClientFrameEdges="Right" ResizeBorderThickness="5"/> </Setter.Value> </Setter> <Setter Property="WindowStyle"> <Setter.Value>None</Setter.Value> </Setter> </Style> 

And apply it to window

<Window Height="471" Width="737" WindowStartupLocation="CenterScreen" Style="{StaticResource ChromeWindow}"> <Grid Margin="0,0,0,0" Background="#FF2A2A2A"> </Grid> </Window> 

Screenshot

Window is moving, is resizing, and have nice Windows 11 border style with shadow.

Comments

0

if you can't use WindowChrome:

using System; using System.Runtime.InteropServices; using System.Windows; using System.Windows.Input; using System.Windows.Interop; using System.Windows.Media; namespace resize { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern IntPtr SendMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam); [DllImportAttribute("user32.dll")] public static extern bool ReleaseCapture(); private void WindowResizeNorth(object sender, MouseButtonEventArgs e) { var hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource; SendMessage(hwndSource.Handle, 0x112, (IntPtr)ResizeDirection.Top, IntPtr.Zero); } private void WindowResizeSouth(object sender, MouseButtonEventArgs e) { var hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource; SendMessage(hwndSource.Handle, 0x112, (IntPtr)ResizeDirection.Bottom, IntPtr.Zero); } private void WindowResizeWest(object sender, MouseButtonEventArgs e) { var hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource; SendMessage(hwndSource.Handle, 0x112, (IntPtr)ResizeDirection.Left, IntPtr.Zero); } private void WindowResizeEast(object sender, MouseButtonEventArgs e) { var hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource; SendMessage(hwndSource.Handle, 0x112, (IntPtr)ResizeDirection.Right, IntPtr.Zero); } private enum ResizeDirection { Left = 61441, Right = 61442, Top = 61443, Bottom = 61446, BottomRight = 61448, } private void BorderVertical_OnMouseEnter(object sender, MouseEventArgs e) { Mouse.OverrideCursor = Cursors.SizeWE; } private void BorderHorizontal_OnMouseEnter(object sender, MouseEventArgs e) { Mouse.OverrideCursor = Cursors.SizeNS; } private void BorderAll_OnMouseLeave(object sender, MouseEventArgs e) { Mouse.OverrideCursor = Cursors.Arrow; } private void BorderSouthEast_OnMouseEnter(object sender, MouseEventArgs e) { Mouse.OverrideCursor = Cursors.SizeNWSE; } private void UIElement_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { var hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource; SendMessage(hwndSource.Handle, 0x112, (IntPtr)ResizeDirection.BottomRight, IntPtr.Zero); } } } 

Xaml:

<Window x:Class="resize.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:resize" mc:Ignorable="d" WindowStyle="None" AllowsTransparency="True" Title="MainWindow" Height="450" Width="800"> <Window.TaskbarItemInfo> <TaskbarItemInfo /> </Window.TaskbarItemInfo> <Grid> <Border MouseLeftButtonDown="WindowResizeEast" MouseEnter="BorderVertical_OnMouseEnter" MouseLeave="BorderAll_OnMouseLeave" VerticalAlignment="Stretch" HorizontalAlignment="Right" Width="1" Background="Black"/> <Border MouseLeftButtonDown="WindowResizeWest" MouseEnter="BorderVertical_OnMouseEnter" MouseLeave="BorderAll_OnMouseLeave" VerticalAlignment="Stretch" HorizontalAlignment="Left" Width="1" Background="Black"/> <Border MouseLeftButtonDown="WindowResizeNorth" MouseEnter="BorderHorizontal_OnMouseEnter" MouseLeave="BorderAll_OnMouseLeave" VerticalAlignment="Top" HorizontalAlignment="Stretch" Height="1" Background="Black"/> <Border MouseLeftButtonDown="WindowResizeSouth" MouseEnter="BorderHorizontal_OnMouseEnter" MouseLeave="BorderAll_OnMouseLeave" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Height="1" Background="Black"/> <Border VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="20" Height="20" MouseEnter="BorderSouthEast_OnMouseEnter" MouseLeave="BorderAll_OnMouseLeave" MouseLeftButtonDown="UIElement_OnMouseLeftButtonDown"> <Grid> <Path Stroke="Gray" StrokeThickness="1" Data=" M 5 20 L 20 5 M 10 20 L 20 10 M 15 20 L 20 15"/> </Grid> </Border> </Grid> </Window> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.