In visual studio i want to add a second code behind file to a xaml window (my main form). i know i can have another (or as many) files that form partial parts of a class, and if they are in the same project they will be included, but can i make more than one file sit in the expander (in the solution explorer) when i expand the xaml file to see its code behind?
+1
A:
Your project file (.csproj for example) is actually XML. Open the .csproj file from the open file dialog, and you will see how it is structured. You can hand edit the project file from there.
Matt Brunell
2009-09-20 23:55:14
that works, thank you. before :the new code behind file <Compile Include="file.open.cs" />just copied the old dependency info from the other one, now i have two code behinds there. <Compile Include="file.open.cs" > <DependentUpon>file.xaml</DependentUpon> </Compile>cool as, wish i didnt have to go to xml to do it but...
Aran Mulholland
2009-09-21 00:09:51
+2
A:
I blogged about this a few months ago, you will find the explanation in this blog post
Basically, you just need to add a <DependentUpon>
element to your extra code-behind file :
<Compile Include="Window1.Foo.cs">
<DependentUpon>Window1.xaml</DependentUpon>
</Compile>
As a side note : why would you want a second code-behind file ? I think one is bad enough ;). If you use a pattern like MVVM, you will almost never need to write any code-behind...
Thomas Levesque
2009-09-21 00:09:43