XAML 中的命名空间错误中不存在名称 [英] The name does not exist in the namespace error in XAML

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

问题描述

使用 VS2012 处理 VB.NET WPF 应用程序.我有一个简单的 MusicPlayer 教程应用程序,用于学习 WPF.我正在逐步将教程的 C# 版本转换为 VB.NET.

Using VS2012 working on a VB.NET WPF application. I have a simple MusicPlayer tutorial app I am using to learn WPF. I am converting a C# version of the tutorial to VB.NET step by step.

它在应用程序中有 2 个类,它们都在同一个命名空间下.我可以在 XAML 中引用命名空间,但是当我尝试在 XAML 中引用类对象时,出现错误并且无法编译.

It has 2 classes in the app that are both under the same namespace. I am able to reference the namespace in the XAML but when I try to reference the class object in XAML I get an error and I am not able to compile.

奇怪的是,IntelliSense 在通过 xmlns:c= 标记引用命名空间以及使用 <c: 键入类对象时都能正常工作但是该对象带有下划线,并且在尝试构建或在设计器中工作时会产生错误.

Strange thing is that the IntelliSense works fine with both referencing the namespace via the xmlns:c= tag and also when typing the class object using <c: But the object is underlined and errors are generated trying to build or work in the designer.

.vb 类文件位于名为 \Controls 的文件夹中.主项目根命名空间有意留空.类是这样编码的...

The .vb class files are in a folder called \Controls. The Main project Root Namespace is intentionaly left blank. The class is coded like this...

Namespace MusicPlayer.Controls
    Public Class UpdatingMediaElement
       .... code here
    End Public
End Namespace

xaml 看起来像这样

The xaml looks like this

(在 标签中定义的命名空间

(namespace defined in the <Window > tag

xmlns:c="clr-namespace:MusicPlayer.Controls"

(在 中定义的对象)

(object defined in a <Grid> )

  <c:UpdatingMediaElement Name="MyMediaElement" />

(显示错误)命名空间clr-namespace:MusicPlayer.Controls"中不存在名称UpdatingMediaElement".

(error displayed) The name "UpdatingMediaElement" does not exist in the namespace "clr-namespace:MusicPlayer.Controls".

不确定哪里出了问题或如何解决?

Not sure what is wrong or how to fix it?

推荐答案

就我而言,这是因为其他编译错误.当其他错误得到解决时,这个看似相关的错误也从列表中删除.特别是错误列表底部和您最近更改的页面上的错误.

In my case it was because of other compile errors. When other errors have been solved this seemingly related error was also removed from the list. Specially the errors at the bottom of the errors list and on pages you have recently changed.

所以不要直接关注这个错误,先关注其他错误.

So do not pay attention to this error directly and focus on other errors at first.

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

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