开发者

How to attach more than one file to a xaml in solution explorer window

开发者 https://www.devze.com 2023-03-14 07:41 出处:网络
This is what I see in the solution explorer (simple wpf project): This is what I would like to have: There are two files dependent of the MainWindow.xaml

This is what I see in the solution explorer (simple wpf project):

How to attach more than one file to a xaml in solution explorer window

This is what I would like to have:

How to attach more than one file to a xaml in solution explorer window

There are two files dependent of the MainWindow.xaml

The obvious drag & drop of MainWindowViewModel.cs to MainWindow.xaml yields an error

can't move file. Same destination 开发者_如何学Pythonfolder.

How can I achieve this? Should be simple, but I can't find it ...

Thanks for any hints


You can do that from within visual studio as far as i know. You can however manually edit the .csproj file and modify the Compile Include element for your viewmodel like this:

<Compile Include="MainWindowViewModel.cs">
  <DependentUpon>MainWindow.xaml</DependentUpon>
  <SubType>Code</SubType>
</Compile>

I havent actually done this in practice but it should get you what you want. However beware that visual studio might think thats is a generated file and delete it when you save the xamlfile, so make sure you backup your work before trying

-edit-

Did a quick test and it seems to work, visual studio doesnt seem to mind or interfere either.

0

精彩评论

暂无评论...
验证码 换一张
取 消