WPF - 错误:[xxx]“不包含 [zzz] 的定义并且找不到扩展方法 [zzz]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20643149/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF - error: [xxx] "does not contain a definition for [zzz] and no extension method [zzz] could be found
提问by Eric Ouellet
I get an error while compiling:
编译时出现错误:
'SimulatorUi.MainWindow' does not contain a definition for 'UserCtrlSimulator' and no extension method 'UserCtrlSimulator' accepting a first argument of type 'SimulatorUi.MainWindow' could be found (are you missing a using directive or an assembly reference?)
“SimulatorUi.MainWindow”不包含“UserCtrlSimulator”的定义,并且找不到接受“SimulatorUi.MainWindow”类型的第一个参数的扩展方法“UserCtrlSimulator”(您是否缺少 using 指令或程序集引用?)
I got this error while compiling a user control and its owning window in the same project.
在同一项目中编译用户控件及其所属窗口时出现此错误。
Why ?
为什么 ?
采纳答案by Eric Ouellet
The problem is the naming of the userControl in its owning Window. I named as:
问题是 userControl 在其拥有的 Window 中的命名。我命名为:
Name="UserCtrlSimulator"
instead of:
代替:
x:Name="UserCtrlSimulator"
You can find the bug and a more useful error message by removing the reference of that badly named object (remove any reference to the object named without the "x:").
您可以通过删除该名称错误的对象的引用(删除对不带“x:”命名的对象的任何引用)来找到错误和更有用的错误消息。
I can't tell the exact reason why it is like this ??? But my solution works fine.
我不知道为什么会这样的确切原因???但我的解决方案工作正常。
Hope it can help anybody because I lost a lots of time with this weird bug.
希望它可以帮助任何人,因为我在这个奇怪的错误上浪费了很多时间。

