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?
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.
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...
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.
one such reason is code organization. in a lot of MVVM implementations which ..
- don't separate V & VM code by projects)
- have a 1-to-1 between View/Xaml & ViewModel
.. it might be advantageous to have your solution explorer look like:
MyView.xaml
-- MyView.xaml.cs
-- MyViewModel.cs
check out this VisualStudio add-in:
© 2022 - 2024 — McMap. All rights reserved.