加载.NET 3.5 WPF的形式在.NET 2.0应用程序 [英] Loading .net 3.5 wpf-forms in a .net 2.0 application
问题描述
我试图加载和承载WPF控件在.NET 2.0 Windows窗体应用程序。如果安装了.NET 3.5的WPF控件应该只被加载。
I'm trying to load and host a WPF control in a .net 2.0 windows forms application. The WPF control should only be loaded if .net 3.5 is installed.
我发现了一个链接的托管WPF内容在MFC应用程序,这是什么我想这样做,但我的C ++知识的心不是足够能翻译到.NET。
I found a link to Hosting WPF Content in an MFC Application and that is about what I'm trying to do but my C++ knowledge isnt sufficient to be able to 'translate' it to .net.
总之,这里是另一个链接:托管WPF内容在Java应用程序该行的也一样了,但我不知道从哪里开始编写code。在.NET。
Anyway, here is another link: Hosting WPF Content in a Java Application that doest the same again but I dont know where to start writing that code in .net.
推荐答案
我用下面的code加载包含一个3.5 WPF控件在.NET 2.0的Windows窗体主机的DLL。加载的控件包含一个ElementHost的对象。
I used the following code to load a dll containing a 3.5 wpf control in a .net 2.0 windows form host. The control loaded contains a ElementHost object.
Dim dllPath As String = "C:\ProjectsTest\TestSolution\ActiveXUser\bin\Debug\TestControl.dll"
If Not File.Exists(dllPath) Then
Return
End If
Dim versionInformation As String
versionInformation = Environment.Version.Major.ToString + Environment.Version.Minor
Dim loadedAssembly As [Assembly] = [Assembly].LoadFile(dllPath)
Dim mytypes As Type() = loadedAssembly.GetTypes()
Dim t As Type = mytypes(1)
Dim obj As [Object] = Activator.CreateInstance(t)
versionInformation = Environment.Version.Major.ToString + Environment.Version.Minor
Me.Panel1.Controls.Add(obj)
这篇关于加载.NET 3.5 WPF的形式在.NET 2.0应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!