Simple WPF Tool Window Sample

This small package demonstrates how to create a simple WPF tool window with VSXtra. The package has the same functionality as the tool window package created with the VSPackage wizard, but it uses WPF in the background. Thanks to Shawn Hempel for the sample and creating the WpfToolWindowPane!

Points of Interest:

  • Everything uses declarative approach
  • Command handling requires only a simple method decorated with attributes.
  • CommandExecMethod signs that the method is to be executed as a response for a command.
  • The CommandId attribute defines how the command is bound to the method.
  • The command has a ShowToolWindowAction attribute defines a menu action declaratively.
  • Creating a new tool window pane is easy with the ToolWindowPane<TPackage, TUIControl> base class.
  • InitialCaption and BitmapResourceId attributes set up the tool window properties declaratively.
  • You can refer to a resource string in the InitialCaption attribute.

Package source code:

using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Shell;
using VSXtra.Commands;
using VSXtra.Package;

namespace DeepDiver.WPFSimpleToolWindow
  [PackageRegistration(UseManagedResourcesOnly = true)]
  [InstalledProductRegistration(false, "#110", "#112", "1.0", IconResourceID = 400)]
  [ProvideLoadKey("Standard", "1.0", "WPFSimpleToolWindow", "DeepDiver", 1)]
  [ProvideMenuResource(1000, 1)]
  public sealed class WPFSimpleToolWindowPackage : PackageBase
    [CommandId(GuidList.guidWPFSimpleToolWindowCmdSetString, CmdIDs.cmdidShowWPFWindow)]
    private void ShowToolWindow()
Tool window pane source code:

using System.Runtime.InteropServices;
using VSXtra.Windows;

namespace DeepDiver.WPFSimpleToolWindow
  public class MyWPFToolWindow : WpfToolWindowPane<WPFSimpleToolWindowPackage, MyControl>
Tool window WPF UI definition:

<UserControl x:Class="DeepDiver.WPFSimpleToolWindow.MyControl"
    Height="300" Width="300">
      <Button Name="button1" Padding="16" VerticalAlignment="Center" HorizontalAlignment="Center" 
        Click="button1_Click" BorderThickness="0" Background="BlanchedAlmond">
        _Click Me!
Tool window WPF UI source code:

using System.Globalization;
using System.Windows;
using System.Windows.Controls;

namespace DeepDiver.WPFSimpleToolWindow
  public partial class MyControl : UserControl
    public MyControl()

    private void button1_Click(object sender, RoutedEventArgs e)
      MessageBox.Show(string.Format(CultureInfo.CurrentUICulture, "We are inside {0}.button1_Click()", ToString()), "VSXtra WPF Simple Tool Window");


Last edited Feb 7, 2009 at 8:25 AM by INovak, version 3


No comments yet.