If you have a Windows Form containing an ElementHost control and the ElementHost containing a WPF UserControl, then assign this form as a child of a DockableWindow, you can get a dockable window that shows WPF control in Inventor.
Imports Inventor
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Imports System.Windows.Forms
Namespace vbButton
<ProgIdAttribute("vbButton.StandardAddInServer"), _
GuidAttribute("f00de0d0-9de0-46fb-ac94-4e6f8633bbaa")> _
Public Class StandardAddInServer
Implements Inventor.ApplicationAddInServer
' Inventor application object.
Private m_inApp As Inventor.Application
Private myButtonDef As ButtonDefinition
Private Dim addInCLSIDString As String
#Region "ApplicationAddInServer Members"
Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, ByVal firstTime As Boolean) Implements Inventor.ApplicationAddInServer.Activate
' This method is called by Inventor when it loads the AddIn.
' The AddInSiteObject provides access to the Inventor Application object.
' The FirstTime flag indicates if the AddIn is loaded for the first time.
' TODO: Add ApplicationAddInServer.Activate implementation.
' e.g. event initialization, command creation etc.
m_inApp = addInSiteObject.Application
' Retrieve the GUID of this class for later use
Dim addInCLS As GuidAttribute
addInCLS = CType(System.Attribute.GetCustomAttribute(GetType(StandardAddInServer), _
GetType(GuidAttribute)), GuidAttribute)
addInCLSIDString= "{" & addInCLS.Value & "}"
' Create the button definition objects
Dim smallIcon As System.Drawing.Icon
smallIcon = New System.Drawing.Icon(My.Resources.MyCommand1Icon, 16, 16)
Dim largeIcon As System.Drawing.Icon
largeIcon = New System.Drawing.Icon(My.Resources.MyCommand1Icon, 32, 32)
Dim smallPic As IPictureDisp
smallPic = Microsoft.VisualBasic.Compatibility.VB6.IconToIPicture(smallIcon)
Dim largePic As IPictureDisp
largePic = Microsoft.VisualBasic.Compatibility.VB6.IconToIPicture(largeIcon)
myButtonDef = m_inApp.CommandManager.ControlDefinitions.AddButtonDefinition( _
"Test", "vbButton:Btn1", _
CommandTypesEnum.kShapeEditCmdType, _
addInCLSIDString, "test", _
"", smallPic, largePic)
' Link the button objects with the event
AddHandler myButtonDef.OnExecute, AddressOf MyButtonDefinition_OnExecute
' Start UI customization:
If firstTime = True Then
' Access user interface manager
Dim uiManager As UserInterfaceManager
uiManager = m_inApp.UserInterfaceManager
Dim interfaceStyle As InterfaceStyleEnum
interfaceStyle = uiManager.InterfaceStyle
If interfaceStyle = InterfaceStyleEnum.kRibbonInterface Then
' Create our commands in ribbon interface
Dim ribbons As Ribbons
ribbons = uiManager.Ribbons
' Assembly: add our commands in Assembly environment
Dim myRibbon As Ribbon
myRibbon = ribbons.Item("ZeroDoc")
' Get the tabs associated ribbon
Dim ribbonTabs As RibbonTabs
ribbonTabs = myRibbon.RibbonTabs
Dim myTab As RibbonTab
myTab = ribbonTabs.Add("MyAddIn", "vbButton:ButtonTab1", _
addInCLSIDString, "")
' Create a new panel within our new tab
Dim ribbonPanels As RibbonPanels
ribbonPanels = myTab.RibbonPanels
Dim myPanel As RibbonPanel
myPanel = ribbonPanels.Add("My Panel", _
"vbButton:myPanel1", addInCLSIDString, "", False)
' Add two commands to the Clone panel
Dim myPanelCtrls As CommandControls
myPanelCtrls = myPanel.CommandControls
Dim myCloneBtnCmdCtrl As CommandControl
myCloneBtnCmdCtrl = myPanelCtrls.AddButton(myButtonDef, True, True, "", False)
End If
End If
' End UI customization.
End Sub
Private Sub MyButtonDefinition_OnExecute(ByVal Context As Inventor.NameValueMap)
Dim f As Form1 = New Form1(m_inApp, addInCLSIDString)
f.ShowDialog()
End Sub
Public Sub Deactivate() Implements Inventor.ApplicationAddInServer.Deactivate
' This method is called by Inventor when the AddIn is unloaded.
' The AddIn will be unloaded either manually by the user or
' when the Inventor session is terminated.
' TODO: Add ApplicationAddInServer.Deactivate implementation
' Release objects.
Marshal.ReleaseComObject(m_inApp)
m_inApp = Nothing
RemoveHandler myButtonDef.OnExecute, AddressOf MyButtonDefinition_OnExecute
Marshal.ReleaseComObject(myButtonDef)
myButtonDef = Nothing
System.GC.WaitForPendingFinalizers()
System.GC.Collect()
End Sub
Public ReadOnly Property Automation() As Object Implements Inventor.ApplicationAddInServer.Automation
' This property is provided to allow the AddIn to expose an API
' of its own to other programs. Typically, this would be done by
' implementing the AddIn's API interface in a class and returning
' that class object through this property.
Get
Return Nothing
End Get
End Property
Public Sub ExecuteCommand(ByVal commandID As Integer) Implements Inventor.ApplicationAddInServer.ExecuteCommand
' Note:this method is now obsolete, you should use the
' ControlDefinition functionality for implementing commands.
End Sub
#End Region
End Class
End Namespace
Imports Inventor
Namespace vbButton
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
Public Sub New(app As Inventor.Application, addInCLS As String)
MyBase.New
InitializeComponent
Dim uiMgr As UserInterfaceManager =app.UserInterfaceManager
Dim myDockableWindow As DockableWindow = uiMgr.DockableWindows.Add(addInCLS, "MyWindow", "My Add-in Dock")
myDockableWindow.AddChild(Me.Handle)
' Default docking state
If Not myDockableWindow.IsCustomized Then
myDockableWindow.DockingState = DockingStateEnum.kFloat
myDockableWindow.Move(25, 25, myDockableWindow.Height, myDockableWindow.Width)
End If
Me.Visible = true
myDockableWindow.Visible = true
End Sub
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.ElementHost1 = New System.Windows.Forms.Integration.ElementHost()
Me.ButtonCtrl1 = New ButtonCtrl()
Me.SuspendLayout()
'
'ElementHost1
'
Me.ElementHost1.Dock = System.Windows.Forms.DockStyle.Fill
Me.ElementHost1.Location = New System.Drawing.Point(0, 0)
Me.ElementHost1.Name = "ElementHost1"
Me.ElementHost1.Size = New System.Drawing.Size(284, 262)
Me.ElementHost1.TabIndex = 0
Me.ElementHost1.Text = "ElementHost1"
Me.ElementHost1.Child = Me.ButtonCtrl1
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(284, 262)
Me.Controls.Add(Me.ElementHost1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
Friend WithEvents ElementHost1 As System.Windows.Forms.Integration.ElementHost
Friend ButtonCtrl1 As ButtonCtrl
End Class
End Namespace
The following picture is the running result: (The sample WPF control is a just button with formatting text and picture tooltip)