Pablo Galiano : Thursday, March 13, 2008 - Posts

Subscriptions

<September 2010>
SuMoTuWeThFrSa
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

News

Subscribe to Pablo Galiano by Email

Post Categories

Thursday, March 13, 2008 - Posts

Hosting a WPF control inside a ToolWindow

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:

  1. Add a reference to C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\WindowsFormsIntegration.dll
  2. Add a WPF user control
  3. Add a class that inherits from ToolWindowPane (our ToolWindow)
  4. 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

posted Thursday, March 13, 2008 5:50 AM by pga with 1 Comments

VS2008 templates and $if$ directives

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

posted Thursday, March 13, 2008 5:36 AM by pga with 2 Comments

VSSDK Assist March 2008 CTP is OUT!!!

This new version includes several bug fixes and it is compatible with GAX February 2008 RTM.

You can download it from here.

 

Pablo

posted Thursday, March 13, 2008 11:49 AM by pga with 1 Comments