在 WPF 中使用 x:Name 或 Name [英] Using x:Name or Name in WPF
问题描述
我对 x:Name vs Name 的理解是有些控件有 Name 属性,和设置 x:Name 基本一样.
My understanding of x:Name vs Name is that some controls have a Name property, that is basically the same as setting x:Name.
当 Name 可用时,使用 Name 比 x:Name 有优势吗?
Is there an advantage to using Name when it is available over x:Name?
这是我的参考,用于理解 x:姓名与姓名.
Here's my reference for understanding x:Name vs Name.
推荐答案
如果 Name 可用作类的属性,Name 和 x:Name 可以互换用作属性,但如果在同一元素上指定两者,则会导致错误.
If Name is available as a property on the class, Name and x:Name can be used interchangeably as attributes, but an error will result if both are specified on the same element.
来源:x:名称属性
换句话说,你使用哪一个没有区别;只是不要在同一个元素上同时使用两者.
In other words, it makes no difference which one you use; just don't use both on the same element.
这篇关于在 WPF 中使用 x:Name 或 Name的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!