c# – 我最近开始自己学习WPF.声明名称与x:名称有什么区别?

前端之家收集整理的这篇文章主要介绍了c# – 我最近开始自己学习WPF.声明名称与x:名称有什么区别?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
例如,我有这个代码
<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

解决方法

wpfwiki

There is basically no difference
between the two.

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.

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.

原文链接:https://www.f2er.com/csharp/92432.html

猜你在找的C#相关文章