Monday, December 06, 2010

WPF Custom Chrome Library

Introduction
If you’ve ever tried to use WindowStyle=”None” to create a window with a custom chrome, you’ve no doubt noticed that you lose standard Windows functionality.  This article shows how to use the WPF Shell Integration Library to solve most of these problems, and builds on this foundation by adding caption buttons (minimize, maximize/restore, and close) and a window icon control that displays the system menu on click and closes on double-click.

Background

The WPF Shell Integration Library provides an easy way to address the following features that are lost when WindowStyle is set to "None":

  • Click-and-drag to move the window 
  • Click-and-drag borders to resize 
  • Double-click to maximize and restore 
  • Right-click to display system menu 
  • Drag to top to maximize, drag away to unmaximize
  • When maximized, leave the Windows taskbar visible 
However, it doesn't provide much help for the following additional features:
  • Caption buttons (minimize, maximize/restore, close)
  • Caption button hover glow (not addressed in this article)
  • Border shadow (not addressed in this article)
  • Window title abbreviated with ellipsis for smaller window width (not addressed in this article) 
In attempting to creating a fully-functional window with custom chrome, I was unable to find code for existing buttons similar to the standard Windows min/max/close buttons, and I wanted a convenient way to incorporate this capability into future projects, so I created this new library and named it "WPF Custom Chrome Library".

From Standard Chrome to Custom Chrome

Standard Chrome

Read more: Codeproject