locked
CreateToolWindow2 returns null reference to user control object. RRS feed

  • Question

  • I have a call to CreateToolWindow2 that works when the user control is a WinForms user control.

    But, when I switch to a WPF user control, CreateToolWindow2 creates and shows the window correctly, but the 6th parameter, the one passed by "ref", returns null.  Why would that be? Can I get a reference to the user control thru the returned EnvDTE.Window object?

    The WPF user control is part of a class library.  The assembly has a GUID and the "make assembly COM-Visible" box is checked.

       EnvDTE80.Windows2 toolWins;
       EnvDTE.Window toolWin;
       object objTemp = null;
    
       ctlProgId = "ToolWindowControls.MakeCentralContral";
       asmPath = "c:\\src#\\MakeCentral\\ToolWindowControls\\bin\\debug\\ToolWindowControls.dll";
       guidStr = "{C22400F8-87D2-477D-AD81-88264C8D7699}";
       toolWins = (Windows2)InApplicationObject.Windows;
    
       // create the tool window.
       toolWin =
        toolWins.CreateToolWindow2(
        InAddInInstance, asmPath, ctlProgId, "Make Central Tool Window", 
        guidStr, ref objTemp);
    

     

    Sunday, May 9, 2010 11:16 PM

Answers

  • Hi SteveRichter,

    Sorry for the delay.

    You can use Package.FindToolWindow Method to get a toolwindow with ToolWindowPane type. CreateToolWindows2 return a Window type, but not WindowPane type, you don't need to convert these two types.

    About sampe code that creates a visual studio tool windows from a WPF user controls. Please refer to the Weeko sample in CodePlex website in following link:

    http://weeko.codeplex.com/

    Please let me know if you have any comments.

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Steve Richter Thursday, May 20, 2010 2:11 AM
    Tuesday, May 18, 2010 7:44 AM

All replies

  • Hi SteveRichter,

    Thanks for your post.

    As far as I know, you can't get control object of WPF control. All WPF elements on the screen are ultimately backed by a HWND. When you create a WPF Window, WPF creates a top-level HWND, and uses an HwndSource to put the Window and its WPF content inside the HWND. For more information, please check WPF and Win32 Interoperation Overview.

    And if you want to get control object, you can use window form control to host a WPF control, see Walkthrough: Hosting a WPF Composite Control in Windows Forms for details.

    If I misunderstood you, or you have any comments, please feel free to let me know.

     

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, May 10, 2010 10:50 AM
  • I got this reply last week to a question asking if I could use a WPF user control as the control of a ToolWindow:

    It is not required to use winform control to host WPF control in 
    VS 2010. If you create a new package with tool window from
    scratch in VS 2010, a WPF user control will be generated. 
    In your ToolWindowPane, please set the WPF control's 
    instance to its Content property.
    
    Thanks
    
    ----------------------------------------------------------------------------Hongye Sun [MSFT]
    
    What is meant by the ToolWindowPane?  When I look at the members of the EnvDTE.Window returned by CreateToolWindow2, I do not see the "Content" property.

    thanks,
    Monday, May 10, 2010 11:27 AM
  • I got around this problem by have the WPF user control store a reference to itself in a static of the assembly during the UserControl Loaded event. Then from the addin, after the call to CreateToolWindow2, I copy that stored reference to the UserControl from the static ( in the assembly of the WPF user control ) to a static in the Addin.

    Would still like to know what the Content property of the ToolWindowPane is.

    thanks,

     

    Monday, May 10, 2010 11:58 AM
  • Hi SteveRichter,

    ToolWindowPane class derives form WindowPane and inherits the default services WindowPane provides. Content property is a property of WindowPane class, so ToolWindowPane should have this property.

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, May 11, 2010 9:29 AM
  • ToolWindowPane class derives form WindowPane and inherits the default services WindowPane provides. Content property is a property of WindowPane class, so ToolWindowPane should have this property.

    How do I get a reference to ToolWindowPane in my VisualStudio add-in?

    I am calling CreateToolWindow2 to create the tool window. That method returns an EnvDTE.Window type.  Is that also a WindowPane? Intellisense does not show a "Content" property for EnvDTE.Window returned by CreateToolWindow2.

    Does Microsoft have some sample code that creates a visual studio tool window from a WPF user control?

     

    Tuesday, May 11, 2010 12:57 PM
  • Hi SteveRichter,

    Sorry for the delay.

    You can use Package.FindToolWindow Method to get a toolwindow with ToolWindowPane type. CreateToolWindows2 return a Window type, but not WindowPane type, you don't need to convert these two types.

    About sampe code that creates a visual studio tool windows from a WPF user controls. Please refer to the Weeko sample in CodePlex website in following link:

    http://weeko.codeplex.com/

    Please let me know if you have any comments.

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Steve Richter Thursday, May 20, 2010 2:11 AM
    Tuesday, May 18, 2010 7:44 AM