Feeds:
Posts
Comments

Archive for October, 2007

While you can always custom paint the windows title bar, in most cases it ends up being a very messy approach with possible side effects. What I do in WPF is to disable the title bar in the window by setting its WindowStyle to none.

<Window x:Class="..."
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    ...
    MinWidth="700" WindowStyle="None" Icon="...">

I then define a user control that will act as the title bar and place it on top of the window. Adding maximize/restore, minimize, and close buttons is not a biggie. You just need to remember to toggle the maximize button with restore (to match normal windows behavior). All you need to do is to set WindowState to WindowState.Minimized, WindowState.Normal, or WindowState.Maximized as required. You might also want to handle double-click and route it to the maximize/restore handler (again to match windows behavior). The one final step would be to handle title bar based drag. To do that, handle the MouseDown event and do this :-

void TitleBar_MouseDown(object sender, MouseButtonEventArgs e)
{
    if(e.ChangedButton == MouseButton.Left)
        Application.Current.MainWindow.DragMove();
}

Read Full Post »

Follow

Get every new post delivered to your Inbox.