Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add existing xaml files to visual studio 2012

Tags:

I want to add a folder containing xaml and cs files plus other directories to a different project on VS. For some reason when I drag the folder from windows explorer to the project where I will like to place that directory visual studio will not let me. Because of that I am manually adding each file and every time I encounter a directory I have to create it. Maybe it is because I am using team foundation server.

Anyways I am adding the files manually so I click on the folder that I want to add the files on visual studio then click on add existing files. Then I select the xaml and code behind file:

enter image description here

when I click add the files get added but visual studio does not recognize that Bytes.xaml.cs is the code behind!

enter image description here

Do I have to manually add a window then copy and paste the contents of the file?

like image 803
Tono Nam Avatar asked Nov 14 '12 21:11

Tono Nam


People also ask

How do I open XAML files in Visual Studio?

To open the XAML Designer, right-click a XAML file in Solution Explorer and choose View Designer. to switch which window appears on top: either the artboard or the XAML editor.

How do I add XAML?

Just right click the project, choose Add -> Window and that will add a new xaml file along with its corresponding .

Where is XAML file in Visual Studio?

To open this page, choose the Tools menu and then choose Options. To access the XAML Designer property page, choose the XAML Designer node. Settings for the XAML Designer are applied when you open the document. So, if you make changes to the settings, you need to close and then reopen Visual Studio to see the changes.

How do I use XAML files?

How to Open an XAML File. XAML files are used in . NET programming, so they can also be opened with Microsoft's Visual Studio. However, since they're text-based XML files, you can also open one and edit one with Windows Notepad or any other text editor.


2 Answers

Edit your .csproj file to add a "DependentUpon" element below your "Compile" element for the .xaml.cs file so that it will appear "inside" the .xaml file not simply below it.:

<Compile Include="BytesDisplay\SubControls\Bytes.xaml.cs">
  <DependentUpon>Bytes.xaml</DependentUpon>
</Compile>

To easily edit the .csproj file:

Right-click the project and select "Unload Project"
Right-click the project node again and select "Edit [projectname].csproj"
Edit the XML, then close the file
Right-click the project node again and select "Reload Project"
like image 126
Vasanthan Avatar answered Sep 24 '22 08:09

Vasanthan


If you drag-and-drop the .xaml file from Windows Explorer into the Solution Explorer window, it will automatically add the .xaml with the code-behind .cs file.

like image 44
youzer Avatar answered Sep 21 '22 08:09

youzer