In WPF, what are the differences between the x:Name and Name attributes?

前端 未结 15 1282
闹比i
闹比i 2020-11-22 05:19

The title says it all. Sometimes it seems that the Name and x:Name attributes are interchangeable.

So, what are the definitive differences

相关标签:
15条回答
  • 2020-11-22 06:02

    I always use the x:Name variant. I have no idea if this affects any performance, I just find it easier for the following reason. If you have your own usercontrols that reside in another assembly just the "Name" property won't always suffice. This makes it easier to just stick too the x:Name property.

    0 讨论(0)
  • 2020-11-22 06:07

    One of the answers is that x:name is to be used inside different program languages such as c# and name is to be used for the framework. Honestly that is what it sounds like to me.

    0 讨论(0)
  • 2020-11-22 06:07

    Name can also be set using property element syntax with inner text, but that is uncommon. In contrast, x:Name cannot be set in XAML property element syntax, or in code using SetValue; it can only be set using attribute syntax on objects because it is a directive.
    If Name is available as a property on the class, Name and x:Name can be used interchangeably as attributes, but a parse exception will result if both are specified on the same element. If the XAML is markup compiled, the exception will occur on the markup compile, otherwise it occurs on load.

    0 讨论(0)
提交回复
热议问题