Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS2012 - Add WPF existing user control to project

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?

like image 824
user10001110101 Avatar asked Dec 06 '22 07:12

user10001110101


1 Answers

Reed's answer is a good architectural one. If you plan on creating a control that you will reuse in many projects then it's best to use a control library.

Your original question is valid in some situations though. Say you have some source code from the Internet that you've unzipped to your drive. This project contains a .XAML file and its linked .vb file that you want to add to a project.

As you seen, the Visual Studio Solution Explorer doesn't link the files when adding with the "Add Item" dialog. I think this is a bug. I find that if I reload the project, the affiliation is added.

Here's a workaround I use. I drag the files from Windows Explorer /File Explorer onto the project in Solution Explorer. That works correctly the first time. enter image description here

like image 99
Walt Ritscher Avatar answered Dec 11 '22 08:12

Walt Ritscher