简体   繁体   English

创建可供 VB 使用的 C# WPF DLL

[英]Create C# WPF DLL who can be used by VB

I try to create a DLL in C# with the WPF framework.我尝试使用 WPF 框架在 C# 中创建一个 DLL。 I want to use this DLL in VB (on excel) as GUI.我想在 VB(在 excel 上)中使用这个 DLL 作为 GUI。 I develop my DLL on Visual Studio and I created a UserControl WPF Library project.我在 Visual Studio 上开发了我的 DLL,并创建了一个 UserControl WPF 库项目。

The goal is to create GUI interface in C# DLL with WPF and use it on my Visual Basic script.目标是使用 WPF 在 C# DLL 中创建 GUI 界面,并在我的 Visual Basic 脚本中使用它。 For exemple: I want to create 2 buttons with WPF/C#, create a DLL who contains my 2 buttons.例如:我想用 WPF/C# 创建 2 个按钮,创建一个包含我的 2 个按钮的 DLL。 Then, display them in my Visual Basic Window.然后,在我的 Visual Basic 窗口中显示它们。

I created a UserControl WPF project and I place 2 buttons in this UserControl.我创建了一个 UserControl WPF 项目,并在这个 UserControl 中放置了 2 个按钮。 See my xaml code:查看我的 xaml 代码: 代码的 Xaml

My C# class:我的 C# 类: 在此处输入图片说明

My DLL build with success.我的 DLL 构建成功。 Then I run this command for register my DLL:然后我运行这个命令来注册我的 DLL:

regasm /codebase /s WpfControlLibrary1.dll

But after these steps, I don't see the reference of my DLL in VB.但是在这些步骤之后,我在 VB 中没有看到我的 DLL 的引用。 And I can't create on object of type of WpfControlLibrary1.而且我无法在 WpfControlLibrary1 类型的对象上创建。

So my question is...how create a C# DLL with a GUI WPF who can be display in Visual Basic GUI ?所以我的问题是...如何使用可以在 Visual Basic GUI 中显示的 GUI WPF 创建 C# DLL? Should I create a UserControl WPF project in Visual Studio ?我应该在 Visual Studio 中创建一个 UserControl WPF 项目吗? Are there other solutions ?还有其他解决方案吗?

A simple C# DLL without WPF work fine in VB but i don't how to do with WPF GUI...一个没有 WPF 的简单 C# DLL 在 VB 中工作正常,但我不知道如何处理 WPF GUI...

Thank's for any helps ;)感谢任何帮助;)

Not sure about the UserControlLibrary Project.不确定 UserControlLibrary 项目。 However, I have faced one similar situation before where I had to work on a project which was already developed in Vb.net.但是,在我不得不从事一个已经在 Vb.net 中开发的项目之前,我遇到过类似的情况。 So, we were developing new controls in C# and referencing them in Vb.net.因此,我们在 C# 中开发新控件并在 Vb.net 中引用它们。

  1. Create a Class library.创建一个类库。

在此处输入图片说明

  1. Add references: System.xaml, Presentationcore, System.drawing添加引用:System.xaml、Presentationcore、System.drawing

在此处输入图片说明

  1. Add new UserControl item to the solution.将新的 UserControl 项添加到解决方案中。

在此处输入图片说明

  1. After this stage, you can modify your user control as per your wish.在此阶段之后,您可以根据需要修改用户控件。 Open new/existing Vb.net Project and add this .dll (created from C#, containing the usercontrol) as reference.打开新的/现有的 Vb.net 项目并添加此 .dll(从 C# 创建,包含用户控件)作为参考。

  2. Inside Xaml, add reference to the namespace and use the same.在 Xaml 中,添加对命名空间的引用并使用相同的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM