c# - 我最近开始自己学习 WPF。声明 Name 与 x :Name? 时有什么区别

标签 c# wpf

例如,我有这段代码:

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

对比

<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.

关于c# - 我最近开始自己学习 WPF。声明 Name 与 x :Name? 时有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1718814/

相关文章:

c# - WPF - 如何判断引发 ComboBox_SelectionChanged 事件的原因

c# - 使用在 Threadpool 线程上创建的 BitmapImage

c# - 为什么位置模式不适用于只有一个位置参数的记录?

c# - 从类上的 void 获取字符串值无法正确输出

c# - 从 XslCompiledTransform.Transform 输出中排除 XML 指令

wpf - 如何显示来自 WPF 应用程序的 Toast 通知?

c# - 我应该如何正确命名 "umbrella"类型?

c# - 检查网络驱动器是否存在并在 C# 中超时

C# 如何在 WPF 中将 ListView 导出为 .CSV?

c# - 如何级联新窗口打开的位置?