我最近开始对我自己的学习WPF。名称:声明名称时对x是有什么区别? [英] I've recently started learning WPF on my own. What is difference when declaring Name vs. x:Name?

查看:132
本文介绍了我最近开始对我自己的学习WPF。名称:声明名称时对x是有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比如说,我有这样的代码:

For instance, I have this code:

<Grid>
    <Rectangle Name="TheRectangle" Fill="AliceBlue" Height="100" Width="100">            
    </Rectangle>
</Grid>



VS

<Grid>
    <Rectangle x:Name="TheRectangle" Fill="AliceBlue" Height="100" Width="100">            
    </Rectangle>
</Grid>



非常感谢您的信息。我对学习新的东西像这样感到非常兴奋。 :D

Thank you very much for the information. I'm very excited about learning something new like this. :D

推荐答案

wpfwiki

有基本上没有区别
。在两者之间

There is basically no difference between the two.

的X:名称的表达在
XAML用于将名称分配给一个目的
将用于向从代码隐藏访问对象

The "x:Name" expression is used in XAML to assign a name to an object that will be used to access the object from the code-behind.

框架的很多类暴露出
Name属性,这不正是
本。对于这些类中,X:名称
和Name属性可以用
互换

Many classes of the framework expose a Name property, which does exactly this. For these classes, both x:Name and the Name property can be used interchangeably.

这篇关于我最近开始对我自己的学习WPF。名称:声明名称时对x是有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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