名称 - 在命名空间中不存在“clr-namespace:..” [英] The name -- doesnot exist in namespace "clr-namespace:.."

查看:886
本文介绍了名称 - 在命名空间中不存在“clr-namespace:..”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在网上尝试了这个问题的所有解决方案,但没有一个工作。我已经定义了命名空间如下:

I have tried every solution on web for this question but none of them worked.I have defined namespace as follows:

xmlns:local="clr-namespace:ScheduleView;assembly=ScheduleView"





然后在



and then in

<Window.Resources>
        <local:ViewModel x:Key="ViewModel"/>
</Window.Resources>







ViewModel.cs文件也在同一名称空间中,ScheduleView和类是公共的。

那么什么错了?为什么VS显示此错误?




the ViewModel.cs file is also in same namespace ScheduleView and class is public.
then whats wrong? why it VS is showing this error ?

推荐答案

可能这是因为您将C#/ .NET命名空间与XAML命名空间混淆。是的,它们被映射在一起,但它应该在您的XAML顶级元素的命名空间声明中指定。 Intellisense帮助您选择写入:当您开始输入以xmlns:x开头的属性(其中x是您计划使用的任何唯一名称空间前缀)时,Intellisense将显示列表在文本插入点右侧的选择。试试看。映射到正确的.NET命名空间的属性值将以正确的语法编写。



有关背景信息,请参阅此MSDN文章: https://msdn.microsoft .com / zh-CN / library / ms747086%28v = vs.110%29.aspx [ ^ ]。



-SA
Probably, this is because you are confusing C#/.NET namespaces with XAML namespaces. Yes, they are mapped together, but it should be specified in your XAML top element's namespace declarations. Intellisense helps you to choose the write one: when you start typing in the attribute starting with "xmlns:x " (where x is any unique namespace prefix you are planning to use, Intellisense will show you the list of choices on the right of text insertion point. Just try it to see. The attribute value mapped to correct .NET namespace will be written in correct syntax for you.

For background, please see this MSDN article: https://msdn.microsoft.com/en-us/library/ms747086%28v=vs.110%29.aspx[^].

—SA


您是否复制了视图并将其粘贴?这有时会出现问题。

尝试从头开始创建视图。
Did you copy the view and paste it? This gives a problem at times.
Try creating the view from scratch again.


这篇关于名称 - 在命名空间中不存在“clr-namespace:..”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆