Why can't I use the Name attribute on UserControl in the same assembly?

前端 未结 2 975
再見小時候
再見小時候 2020-12-14 06:52

When I created a WPF UserControl and tried to use it, I got the following compiler error:

Because \'UserControl1\' is implemented in the

2条回答
  •  爱一瞬间的悲伤
    2020-12-14 07:38

    x:Name is simply a more explicit way of saying "The name attribute in this specific XML namespace". The fact that WPF can't compile it without being given this hint because it's in the same assembly is just a limitation of how they wrote the parser.

    If you are asking why it is this way, I do not know for sure because I didn't write it. It probably has something to do with it needing to be able to resolve the Name attribute (read: Dependency Property) to something concrete BEFORE building your UserControl1, in other words, a catch-22.

提交回复
热议问题