If you have downloaded StickyNotes you already noticed that the main toolwindow is hosting a WPF control.
Let see the steps needed to host a WPF control in a VS Toolwindow:
- Add a reference to C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\WindowsFormsIntegration.dll
- Add a WPF user control
- Add a class that inherits from ToolWindowPane (our ToolWindow)
- Modify the ToolWindowPane class as follows:
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using Microsoft.VisualStudio.Shell;
[Guid("2070F92C-0843-4ba2-A46E-D559B1F03B2F")]
public class MyToolwindow : ToolWindowPane
{
private ElementHost elementHost;
public MyToolwindow:
base(null)
{
this.Caption = "My Tool Window";
}
protected override void Initialize()
{
base.Initialize();
elementHost = new ElementHost();
elementHost.Child = new MyWPFControl();
}
override public IWin32Window Window
{
get
{
return (IWin32Window)elementHost;
}
}
}
That's all you need,
Pablo
Today I found that the VS 2008 new wizard template engine supports $if$ directives. This was supported in the old .vsz format but now it is also available in vstemplates.
If we take a look at the existing windows form item template provided with VS 2008 we can see:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
$if$ ($targetframeworkversion$ == 3.5)using System.Linq;
$endif
$using System.Text;
using System.Windows.Forms;
namespace $rootnamespace$
{
public partial class $safeitemrootname$: Form
{
public $safeitemrootname$()
{
InitializeComponent();
}
}
}
Really cool, isn't it?
Pablo
This new version includes several bug fixes and it is compatible with GAX February 2008 RTM.
You can download it from here.
Pablo