VS2012 - 将 WPF 现有用户控件添加到项目 [英] VS2012 - Add WPF existing user control to project

查看:38
本文介绍了VS2012 - 将 WPF 现有用户控件添加到项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这看起来应该很简单,但我似乎无法实现.假设我有一个名为 uc1 的用户控件的现有项目.我想在另一个项目中使用这个用户控件.我在解决方案资源管理器中右键单击项目名称并选择添加>现有项目,将下拉列表更改为所有文件并选择文件 uc1.xaml 和 uc1.xaml.vb.这当然会将文件添加到项目中,但是 xaml 和代码隐藏文件之间没有关联,并且无法使用控件.这样做的正确方法是什么?

This seems like it should be pretty simple but I can't seem to make it happen. Lets say I have an existing project with a user control named uc1. I would like to use this user control in another project. I right-click the project name in the solution explorer and select add>existing item, change the drop down to all files and select the files uc1.xaml and uc1.xaml.vb. This of course adds the files to the project but there is no correlation between the xaml and the code behind file and there is no way to use the control. What is the proper way of doing this?

推荐答案

这当然是将文件添加到项目中,但是 xaml 和代码隐藏文件之间没有关联,也无法使用控件.这样做的正确方法是什么?

This of course adds the files to the project but there is no correlation between the xaml and the code behind file and there is no way to use the control. What is the proper way of doing this?

通常,您会添加对其他项目的引用,并直接使用 UserControl.

Normally, you'd add a reference to the other project, and use the UserControl directly.

这允许您使用 UserControl 构建单个项目,并在多个项目中使用生成的程序集 (DLL)而无需复制代码.

This allows you to build a single project with your UserControl, and use the resulting assembly (DLL) in multiple projects without duplicating the code.

这篇关于VS2012 - 将 WPF 现有用户控件添加到项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆