Click here to Skip to main content
13,091,537 members (62,786 online)
Click here to Skip to main content
Add your own
alternative version


4 bookmarked
Posted 21 Jul 2014

WPF C# / VB.NET Additional (fourth) button on window titlebar (Aero only!)

, 22 Jul 2014
Rate this:
Please Sign up or sign in to vote.
Using WindowChrome from Microsoft.Windows.Shell.dll


This code demonstrates how you can easily add an additional button (such as Help "?" button) to WPF Window titlebar.

Attention: this code works properly in Windows Vista, 7, 8, 8.1 only, and if Aero theme (or its equivalent theme, so as standart theme in Windows 8 or in Window 7 Home Basic) is enabled.

Prepaire your Project

Add reference to Microsoft.Windows.Shell.dll to your WPF Project.

Window XAML code

<Window x:Class="!!!PLEASE_PASTE_YOUR_NAMESPACE!!!.Window1"




    Title="Window1" Height="300" Width="300">

        <Style TargetType="{x:Type Window}">
            <Setter Property="shell:WindowChrome.WindowChrome">
                    <shell:WindowChrome />
            <Setter Property="Template">
                    <ControlTemplate TargetType="{x:Type Window}">
                            <!-- window background (covers black) -->
                            <Border Background="White" Margin="{Binding Source={x:Static shell:SystemParameters2.Current}, Path=WindowNonClientFrameThickness}">
                                <ContentPresenter Content="{TemplateBinding Content}" />
                            <!-- fouth button! -->
                            <Button Name="btnHelp" Focusable="False" Height="25" HorizontalAlignment="Right" Margin="0,0,120,0" VerticalAlignment="Top" Width="40" shell:WindowChrome.IsHitTestVisibleInChrome="True">?</Button>


Window code-behind code in C#.NET

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;

namespace CSHARP_Additional__fourth__button_on_window_frame
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
        public Window1()

        public override void OnApplyTemplate()
            var oDep = GetTemplateChild("btnHelp");
            if (oDep != null)
                ((Button)oDep).Click += this.btnHelp_Click;


        private void btnHelp_Click(System.Object sender, System.Windows.RoutedEventArgs e)
            MessageBox.Show("Help", "", MessageBoxButton.OK, MessageBoxImage.Information);

        //Service provided by Telerik (
        //Conversion powered by NRefactory.
        //Twitter: @telerik

Window code-behind code in VB.NET

Class Window1 

    Public Overrides Sub OnApplyTemplate()
        Dim oDep = GetTemplateChild("btnHelp")
        If oDep IsNot Nothing Then
            AddHandler CType(oDep, Button).Click, AddressOf Me.btnHelp_Click
        End If

    End Sub

    Private Sub btnHelp_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        MessageBox.Show("Help", _
                        "", _
                        MessageBoxButton.OK, _
    End Sub

End Class


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170813.1 | Last Updated 22 Jul 2014
Article Copyright 2014 by Emiliarge
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid