.xaml 和 .xaml.cs 文件之间有什么联系 [英] What is the connection between .xaml and .xaml.cs files

查看:66
本文介绍了.xaml 和 .xaml.cs 文件之间有什么联系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于一个视图,有对应的 .xaml 和一个 .xaml.cs 文件.这些文件是如何关联的?

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

我是 xaml 的新手 - 我想我在 .xaml 文件中看到了动态占位符,但显式引用了文件作为相应 .cs 文件以外的源.我想我看到了控制器视图行为,其中用户交互触发了视图上的状态更改,类似于 Javascript/CSS UI 交互.

I'm super new to xaml - I think I see dynamic placeholders in the .xaml files, but with explicit references to files as sources other than the corresponding .cs file. I think I see controller-view behavior, where user interaction triggers state changes on the view comparable to Javascript/CSS UI interactions.

推荐答案

XAML 文件 (.xaml) 和相应的代码隐藏文件 (.xaml.cs) 是同一类的两个部分定义.

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

部分类和方法(C# 编程指南): https://msdn.microsoft.com/en-us/library/wa80x488.aspx

在运行时在代码隐藏类的构造函数中调用的 InitializeComponent() 方法将 URI 定位到已编译的 XAML 文件,并将其传递给解析 BAML(即已编译的 XAML)的 L​​oadComponent() 方法,以及创建您在 XAML 标记中定义的元素的实例.请参阅以下链接了解更多信息.

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.

InitializeComponent() 有什么作用,以及它在 WPF 中是如何工作的?

这篇关于.xaml 和 .xaml.cs 文件之间有什么联系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆