How can I connect xaml and xaml.cs files

This is simple, try to add in project existing items and select the XAML (not .cs, etc.) files in list of formats. In VS2010 thats helps.


Easiest Way!!!

I came across the same. I got the way out. Here is how to get the .xaml.cs nested under the .xaml in Solution Explorer:

  1. In Windows File Explorer (outside of Visual Studio), open the folder where the required files are.
  2. Select both files (.xaml and .xaml.cs) together.
  3. Drag it onto your project name in the Solution Explorer.
  4. Its done! :)

If you cannot get the IDE to do it (Papa John's post), then you can do it by editing the project file.

That information is in the .csproj file (which is an XML file -- you can open it in a text editor, or by right-clicking on it, choosing "unload", and then opening it -- choose reload to load it up as a project again).

Here is the information to look for, you would need to add the "DependentUpon" tag.

<Compile Include="TheFile.xaml.cs">
  <DependentUpon>TheFile.xaml</DependentUpon>
</Compile>

Tags:

C#

.Net

Wpf

Xaml