If you set ResizeMode="CanResizeWithGrip"
on a WPF Window
then a resize grip is shown in the lower right corner, as below:
If you set WindowStyle="None"
as well the title bar disappears but the grey bevelled edge remains until you set ResizeMode="NoResize"
. Unfortunately, with this combination of properties set, the resize grip also disappears.
I have overridden the Window
's ControlTemplate
via a custom Style
. I want to specify the border of the window myself, and I don't need users to be able to resize the window from all four sides, but I do need a resize grip.
Can someone detail a simple way to meet all of these criteria?
- Do not have a border on the
Window
apart from the one I specify myself in aControlTemplate
. - Do have a working resize grip in the lower right corner.
- Do not have a title bar.
If you set the
AllowsTransparency
property on theWindow
(even without setting any transparency values) the border disappears and you can only resize via the grip.Result looks like:
Sample here:
I was trying to create a borderless window with
WindowStyle="None"
but when I tested it, seems that appears a white bar in the top, after some research it appears to be a "Resize border", here is an image (I remarked in yellow):After some research over the internet, and lots of difficult non xaml solutions, all the solutions that I found were code behind in C# and lots of code lines, I found indirectly the solution here: Maximum custom window loses drop shadow effect
Note : You need to use .NET 4.5 framework, or if you are using an older version use WPFShell, just reference the shell and use
Shell:WindowChrome.WindowChrome
instead.I used the
WindowChrome
property of Window, if you use this that white "resize border" disappears, but you need to define some properties to work correctly.CaptionHeight: This is the height of the caption area (headerbar) that allows for the Aero snap, double clicking behaviour as a normal title bar does. Set this to 0 (zero) to make the buttons work.
ResizeBorderThickness: This is thickness at the edge of the window which is where you can resize the window. I put to 5 because i like that number, and because if you put zero its difficult to resize the window.
After using this short code the result is this:
And now, the white border disappeared without using
ResizeMode="NoResize"
andAllowsTransparency="True"
, also it shows a shadow in the window.Later I will explain how to make to work the buttons (I didn't used images for the buttons) easily with simple and short code, Im new and i think that I can post to codeproject, because here I didn't find the place to post the tutorial.
Maybe there is another solution (I know that there are hard and difficult solutions for noobs like me) but this works for my personal projects.
Here is the complete code
Thank you!
While the accepted answer is very true, just want to point out that AllowTransparency has some downfalls. It does not allow child window controls to show up, ie WebBrowser, and it usually forces software rendering which can have negative performance effects.
There is a better work around though.
When you want to create a window with no border that is resizeable and is able to host a WebBrowser control or a Frame control pointed to a URL you simply couldn't, the contents of said control would show empty.
I found a workaround though; in the Window, if you set the WindowStyle to None, ResizeMode to NoResize (bear with me, you will still be able to resize once done) then make sure you have UNCHECKED AllowsTransparency you will have a static sized window with no border and will show the browser control.
Now, you probably still want to be able to resize right? Well we can to that with a interop call:
And voila, A WPF window with no border and still movable and resizable without losing compatibility with with controls like WebBrowser