Click here to Skip to main content
15,885,767 members
Articles / Desktop Programming / WPF

WPF Custom Chrome Library

Rate me:
Please Sign up or sign in to vote.
4.78/5 (32 votes)
3 Dec 2010Ms-PL4 min read 157.8K   12.9K   87  
Create fully functional windows with custom chrome and caption buttons in WPF
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Windows.Shell;

namespace CustomChromeLibrary
{
	public class WindowIcon : ContentControl
	{
		static WindowIcon()
		{
			DefaultStyleKeyProperty.OverrideMetadata(typeof(WindowIcon), new FrameworkPropertyMetadata(typeof(WindowIcon)));
		}

		protected override void OnMouseDown(MouseButtonEventArgs e)
		{
			base.OnMouseDown(e);
			Window w = Window.GetWindow(this);
			if (e.ClickCount == 1)
			{
				Point p;
				if (e.ChangedButton == MouseButton.Left)
				{
					p = this.PointToScreen(e.GetPosition(this));
					p.X += 1;
					p.Y += 1;
				}
				else
				{
					p = this.PointToScreen(e.GetPosition(this));
					p.X += 1;
					p.Y += 1;
				}
				SystemCommands.ShowSystemMenu(w, p);
			}
			if (e.ClickCount == 2 && e.ChangedButton == MouseButton.Left)
				w.Close();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Architect
United States United States
Greg has been working in software development in a variety of roles since 1990.

Comments and Discussions