开发者

Using x:Name or Name in WPF [duplicate]

开发者 https://www.devze.com 2022-12-14 04:59 出处:网络
This question already has answers here: 开发者_运维百科 In WPF, what are the differences between the x:Name and Name attributes?
This question already has answers here: 开发者_运维百科 In WPF, what are the differences between the x:Name and Name attributes? (15 answers) Closed 8 years ago.

My understanding of x:Name vs Name is that some controls have a Name property, that is basically the same as setting x:Name.

Is there an advantage to using Name when it is available over x:Name?

Here's my reference for understanding x:Name vs Name.


For any that has stumbled upon this question ... here's is a very detailed answer. Thanks to Taylor L for pointing me in the right direction.


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.

Source: x:Name Attribute

In other words, it makes no difference which one you use; just don't use both on the same element.


You're safer using x:Name because it works all the time, where as Name depends on the particular control implementation.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号