Window1.xaml -> Window1.xaml.cs - how do I get this hierarchially ordered
-
When I create open WPF program examples I see Window1.xaml and a Window1.xaml.cs file neatly grouped together, the .cs files having a link arrow showing the relation or depency between the two files. But when I add a xaml file, paste some xml (xaml) into it from another project, I have to create a separate class file Window1.xaml.cs for example. This file, when added as a new item, is in the same tree hierarchy than the .xaml file and is not showing this arrow icon. Am I doing something wrong? -- Christoph
-
When I create open WPF program examples I see Window1.xaml and a Window1.xaml.cs file neatly grouped together, the .cs files having a link arrow showing the relation or depency between the two files. But when I add a xaml file, paste some xml (xaml) into it from another project, I have to create a separate class file Window1.xaml.cs for example. This file, when added as a new item, is in the same tree hierarchy than the .xaml file and is not showing this arrow icon. Am I doing something wrong? -- Christoph
-
When I create open WPF program examples I see Window1.xaml and a Window1.xaml.cs file neatly grouped together, the .cs files having a link arrow showing the relation or depency between the two files. But when I add a xaml file, paste some xml (xaml) into it from another project, I have to create a separate class file Window1.xaml.cs for example. This file, when added as a new item, is in the same tree hierarchy than the .xaml file and is not showing this arrow icon. Am I doing something wrong? -- Christoph
In visual studio if you right click on your project and select "Add"->"New Item" and then select a WPF window, or user control visual studio will automatically add both the xaml and the xaml.cs files which you can paste your code into. However, if this doesn't suit you, or they somehow become disconnected - which does seem to happen sometimes - you can reattach them like this: 1) Right click on the project and select "Unload project" 2) Now your project is unloaded, right click again and select "Edit [projectname].csproj". 3) This will open the the project file for editing manually, it's just a regular xml file so is fairly easy to read. 4) Search within the xml of the csproj file for the name of your unlinked files. 5) To link a .xaml file with it's child .xaml.cs file it should look something like this:
<Page Include="Window1.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> <Compile Include="Window1.xaml.cs"> <DependentUpon>Window1.xaml</DependentUpon> </Compile>
(You may find that the two files are not next to each other in the .csproj file.) If they are not correctly linked, you may find that the .xaml.cs reference is missing the dependant tag. If you just added them as regular files, you may also find the tags aren't quite correct. 6) You just need to edit you file to match this layout. 7) Now save the .csproj file. Right click on the project and select "Reload project". You two files should now be linked.
Simon