Title less Windows in WPF
Back in the Win Forms days we had to do a lot of tricks in order to have a title less Window. One (and I believe the best) approach to do this was to override the WndProc and handle the messages to trick windows in thinking that there is a Title. Something like this
1: private const int WM_NCHITTEST = 0x84;
2: private const int HTCLIENT = 0x1;
3: private const int HTCAPTION = 0x2;
4:
5: protected override void WndProc(ref Message message)
6: {
7:
8: base.WndProc(ref message);
9:
10: if (message.Msg == WM_NCHITTEST && (int)message.Result == HTCLIENT)
11: message.Result = (IntPtr)HTCAPTION;
12:
13: }
This is quite cool and clean… But WPF gives is a nicer way how to do it….
So first of all we need to set the WindowStyle property of the Window to None. It would look something like this
1: <Window x:Class="TitleLessWindow.Window1"
2: xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4: Title="Window1" Height="300" Width="300" WindowStyle="None">
5: </Window>
Now the problem is that the user cannot drag the window around. In order to do this we just have to write 1 line of code…. yes 1 line of code
THANKS WPF
MouseDown += delegate { DragMove(); };
1: MouseDown += delegate { DragMove(); };
Put that line of code in the constructor of the Window and that’s it
Now the user can drag the window around without any problem
I suggest that you also have a look at this brilliant post about Custom windows





[...] Title less Windows in WPF (Marlon Grech) [...]
Pingback by Dew Drop - February 28, 2009 | Alvin Ashcraft's Morning Dew | March 1, 2009 |
Just passing by.Btw, your website have great content!
_________________________________
Making Money $150 An Hour
I think you need to put
this.MouseLeftButtonDown += delegate { DragMove(); };
else you will get an InvalidOperationException on right-click that you can only call DragMove when primary mouse button is down.
Also, I am not sure about anyone else, but I am getting in redrawing problems in Win 7 using the WindowStyle in “None” mode.
Usually you’d want to set your Window’s style in a resource, in which case you’d need a Command to initialize the dragging and keep the codebehind clear. Also, when your app goes to the “not responding mode”, the border and the title bar are back…
hi very greate and cool stuff keep post more
[...] Source: http://marlongrech.wordpress.com/2009/02/27/title-less-windows-in-wpf/ [...]
Pingback by Dragging a Titleless Window in WPF « Various Rants | February 27, 2010 |