I wouldn't worry about that too much if I were you. It's a completely IDE-related matter that does not really affect you in any way.
Yet, let me explain that to you real quick:
When you add a UserControl
or Window
in a WPF Project by using the Visual Studio Add -> New Item..
action, Visual Studio adds 3 files to your project:
1 - MyUserControl.xaml
Is the XAML file, which contains the XAML that comprises your UserControl.
2 - MyUserControl.xaml.cs
, which is the "code behind" file, that defines a public partial class
derived from System.Windows.Controls.UserControl
, which allows you to create additional logic for the interaction with your UserControl
.
3 - Under the covers, another file called MyUserControl.g.i.cs
is also generated. This file contains the same class as #2, also defined as partial
, and additionally contains the definition of all the fields
inside the class for any relevant XAML-defined elements that were given an x:Name
.
This means that if your XAML contains something like this:
<TextBox x:Name="TextBox1"/>
the .g.i.cs
file will contain a declaration like this:
internal System.Windows.Controls.TextBox TextBox1;
the value of this field is assigned via WPF's internal mechanisms that I will not discuss right now.
The bottom line is that the code you may write in the MyUserControl.xaml.cs
code behind file is probably going to make use of the class members defined in .g.i.cs
(such as TextBox1
), and since that file is dependent on the XAML file, so is your code behind file.
That's why the code behind file is set as DependentUpon the XAML file in the Project Schema, which if you look at the csproj
file, looks something like this:
<!-- ... -->
<ItemGroup>
<Page Include="MyUserControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="MyUserControl.xaml.cs">
<DependentUpon>MyUserControl.xaml</DependentUpon>
<!-- notice how this file is defined as DepedentUpon the XAML file -->
</Compile>
</ItemGroup>
<!-- ... -->