What is the connection between .xaml and .xaml.cs files

后端 未结 3 1905
醉酒成梦
醉酒成梦 2021-01-23 12:41

For a view, there are corresponding .xaml and a .xaml.cs files. How are these files related?

I\'m super new to xaml - I think I see dynamic placeholders in the .xaml fil

相关标签:
3条回答
  • 2021-01-23 13:28

    .xaml is the designer file and .xaml.cs is the code-behind file where you write the business logic instead of inline code in .xaml. This provides more flexiblity of code separation and code readability.

    0 讨论(0)
  • 2021-01-23 13:32

    For an application using a MVVM (Model View ModelView) implementation:

    • View: *.xaml
    • ViewModel: *.xaml.cs
    0 讨论(0)
  • 2021-01-23 13:35

    The XAML file (.xaml) and the corresponding code-behind file (.xaml.cs) are two partial definitions of the same class.

    Partial Classes and Methods (C# Programming Guide): https://msdn.microsoft.com/en-us/library/wa80x488.aspx

    The InitializeComponent() method that is called in the constructor of the code-behind class at runtime locates a URI to the compiled XAML file and passes it to a LoadComponent() method that parses the BAML, i.e. the compiled XAML, and creates instances of the elements that you have defined in your XAML markup. Please refer to the following link for more information about this.

    What does InitializeComponent() do, and how does it work in WPF?

    0 讨论(0)
提交回复
热议问题