it works if encapsulate within a winform... using ElementHost
look better than winform, but adds an extra layer to manage in your interface.
cheers
I know this is an old post but yes you can create add-ins using 100% WPF.
I have several WPF Class Library .Net 4.5 add-ins that work with Inventor 2012+.
You do not have to encapsulate within a winform.
What are you looking for specifically in a code example? How to set up registry free add-in or how to create a WPF Class library?
-Addam
How to create a WPF Class library? Boorda - The image you posted shows it but Visual Studio 2013 doesn't have that option. Can you please elaborate on that process how to setup a WPF Class Library?
Hi @Boorda, I know it's been a long time since you posted this reply but I would love to see what you have created in regards to the WPF implementation.
I have been attempting to get this working recently and the best I can manage is a new dockable window that contains a black box.
Thanks,
Alex.
that's no problem @Anonymous; your reply in the other thread might be able to help me with the "no tab key" issue I am having with another addin...
Do you have your solution hosted anywhere like Github that I could take a look at?
@Rab_i I'm really sorry, I didn't see you post 9 months ago. You may have already figured it out by now, but in case you didn't here's how to create a WPF Class library....
Your project should now be a buildable WPF Class Library.
@AlexFielder, what are you having issues with exactly? Are you trying to get a button to show up in the ribbon somewhere?
If so, I have a few base classes that I have written that can setup TABs, PANELs, and Control Definitions (Buttons) just by supplying a few parameters.
I try to practice DRY programming, in other words Don't Repeat Yourself. So i create base classes out of code that becomes repetitive.
Since there are still questions about WPF Add-ins, in a few days I will post an Inventor WFP Add-in Project template with some setup instructions.
-Addam
Hmmm, I haven't really messed with dockable windows yet in WPF. I will play around with them and let you know if I can manage to get something working. In the meantime, instead of using a WPF Window in the dockable window, maybe try to just display a WPF User Control. Not sure if that will work, but it's worth trying.
-Addam
There's this article which details doing just that (WPF control inside a Winform):
And here's an article by @adam.nagy where he uses WPF inside an Inventor Add-in (albeit not in a dockable window):
http://adndevblog.typepad.com/manufacturing/2015/11/wpf-window-inside-an-inventor-add-in.html
I haven't (yet) tried the first approach although I suppose there's no reason why a wpf Window couldn't be set to fill whatever winForm it was assigned to..?
I have been super busy the last week, just wanted to let everyone know I haven't forgotten about posting the WPF template.
I will post it as soon as I can get around to it.
-Addam
@AlexFielder Ok, so on the subject of dockable windows here is what I did.
I wasn't able to get a WPF Window to work so I just created a blank System.Windows.Forms.Form then dropped an ElementHost on it and docked it in the parent container. As far as the design, that's all I had to do. It doesn't matter what size you set the form as it will automatically adjust to fit the dockablewindow. Also, you can do this in a WPF Class Library, I did not have to create an old Windows Forms Class Library. You just need to add a reference to the System.Windows.Forms namespace.
Here is what the Form looks like in the code behind...
Imports Inventor Public Class DWForm Public Sub New(InvApp as Inventor.Application, InternalName As String, WindowTitle As String, WPFControl As UIElement, Optional ShowTitle As Boolean = True) ' This call is required by the designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call.
'Pass the WPFControl to the ElementHost
Me.ElementHost1.Child = WPFControl
'Create the Dockable Window.
Dim DocWin = InvApp.UserInterfaceManager.DockableWindows.Add(CLID, InternalName, WindowTitle)
'Add the current form to the dockable window.
DocWin.AddChild(Me.Handle)
'Controls the Title Bar Visibility. DocWin.ShowTitleBar = ShowTitle
'Make sure the dockable window and the child form are visible. DocWin.Visible = True Me.Visible = True
'Ensure the child window chrome is turned off. Me.FormBorderStyle = Forms.FormBorderStyle.None End Sub End Class
The above class allows you to create dockable windows over and over without having to write this code out every time.You just create a new instance of this class and pass in a unique InternalName and the WPF element to be hosted. It's worth noting that the CLID variable (in red) I have in my add-ins as a global variable with my add-in's CLID, you could change the method signature and add that as a parameter to pass in.
Here is how you create multiple instances of dockable windows, this is in my Activate method....
'Hook into the Inventor Application object... _InvApp = AddInSiteObject.Application
Dim DocFrm1 = New DWForm(_InvApp, "FUTE_DW_1", "Window 1", New QuickProps, False)
Dim DocFrm2 = New DWForm(_InvApp, "FUTE_DW_2", "Window 2", New iPropertyBlock, False)
The QuickProps & iPropertyBlock (in blue) are just WPF User Controls that I have created in my project. I am literally creating them as I pass them into the form. You should build all of you logic and binding into your WPF controls and simply use the form to host it. It may get complicated if you start trying to throw controls on the Windows Form as well.
Anyway, I hope that helps!
Let me know if you have any issues with the code.
-Addam
Hi Addam,
That's great work; thanks for sharing!
Cheers,
Alex.
PS. I'm not surprised you went the route of using the ElementHost, it seems almost impossible to use a vanilla-WPF solution.
Can't find what you're looking for? Ask the community or share your knowledge.