这对我来说是一个偶然的、反复出现的问题。我将对我的项目进行任意更改,然后 VisualStudio 将给我 96 个命名空间错误。它们几乎总是与我的 XAML 命名空间声明有关,但我知道这些类存在于命名空间中。
我已经多次清理、构建和重建,以及重新启动 VS 都没有成功。
示例:
在这种情况下,它是在命名空间 clr-namespace:NineGridViewer 中“不存在”的类 ExpandedConverter。一个可能的问题可能是我将我的项目组织到文件夹中,例如转换器都在 IValueConverters 文件夹中,而 MainWindow 在 Views 文件夹中。但是命名空间没有改变
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:nineGridViewer="clr-namespace:NineGridViewer"
Title="NineGridViewer" Height="900" Width="900">
<Window.Resources>
<nineGridViewer:ExpandedConverter x:Key="ExpandedConverter"/>
<nineGridViewer:StringToBrushConverter x:Key="StringToBrushConverter"/>
</Window.Resources>
namespace NineGridViewer {
/// <summary>
/// Binds the isExpanded property of the UI Expanders to the ViewModel's CurrentExpanded property
/// </summary>
public class ExpandedConverter : IValueConverter
{
public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string input = value as string;
string param = parameter as string;
if (String.IsNullOrEmpty(input) || String.IsNullOrEmpty(param))
{
throw new ArgumentNullException();
}
return Equals(input, param);
}
public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return parameter;
}
}
}
最佳答案
编译错误阻止构建程序集 [ies],因此 Visual Studio 无法检查它们并在 XAML 设计器和其他工具中使用它们。
这就是为什么您会收到所有这些看似缺少类的错误。
应该有一个“根”错误(通常在列表的底部),这是一个真正的编译错误。如果您修复所有其他错误应该在构建时消失。
关于c# - XAML 命名空间上的 "does not exist in namespace"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24533878/