none
VsPackage - ToolWindow - how to use Window.Forms.UserControl instead of Default WPF control

    Question

  • Hi, I have just started learning VSX. So please do not mind if the question looks stupid.

    When we create a new VS Package project with ToolWindow, by default a control MyControl.xaml will be added which will be tied to the ToolWindow.

    How to use a normal usercontrol dervied from Windows.Forms.UserControl?

    I tried added a usercontrol in the project and changed the code in the MyToolWindow.cs to use that control but all I see is blank Toolwindow if i debug.

    //Normal code in auto generated MyToolWindow.cs
    base
    .Content = new MyControl();

    //The usercontrol i created is SimpleControl. I have changed the code to.
    base.Content = new SimpleControl();

    Other details:
    Visual Studio 2010 Premium SP1
    Windows 7 Professional 64 bit.

    Snapshot of the auto generated default project


    Friday, September 14, 2012 5:41 PM

Answers

  • Hi Syed,

    The ToolWindowPane can be used to host WPF content or a Winform control.

    For a Winform control, you just need to override the Window property get, and leave the Content property null.

    For example:

            public MyToolWindow() :  base(null)
            {
                this.Caption = Resources.ToolWindowTitle;
                this.BitmapResourceID = 301;
                this.BitmapIndex = 1;
                control = new MyControl();
            }
     
            override public IWin32Window Window
            {
                get
                {
                    return (IWin32Window)control;
                }
            }

    Sincerely,


    Ed Dore

    Friday, September 14, 2012 9:30 PM
    Moderator

All replies

  • Hi Syed,

    The ToolWindowPane can be used to host WPF content or a Winform control.

    For a Winform control, you just need to override the Window property get, and leave the Content property null.

    For example:

            public MyToolWindow() :  base(null)
            {
                this.Caption = Resources.ToolWindowTitle;
                this.BitmapResourceID = 301;
                this.BitmapIndex = 1;
                control = new MyControl();
            }
     
            override public IWin32Window Window
            {
                get
                {
                    return (IWin32Window)control;
                }
            }

    Sincerely,


    Ed Dore

    Friday, September 14, 2012 9:30 PM
    Moderator
  • Hi Syed,

    I marked Ed's reply as answer.

    Please unmark it, if it is not the answer.

    Thank you for your understanding and support.

    Best regards,


    Ego [MSFT]
    MSDN Community Support | Feedback to us

    Monday, September 24, 2012 9:18 AM
    Moderator
  • Yes, it is. I should have done that myself. Sorry for being lazy and thanks for doing this.

    Aziz ur Rahman http://www.dotnetpanda.com

    Monday, September 24, 2012 1:20 PM