XAML名称空间中的"名称空间中不存在"错误

Wil*_*ler 9 c# wpf xaml visual-studio visual-studio-2012

这对我来说是偶然的,反复出现的问题.我将对我的项目进行任意更改,然后VisualStudio将给出96个命名空间错误.它们几乎总是出现我的XAML名称空间声明错误,但我知道这些类存在于名称空间中.

我已经清理和构建,并重建了很多次,并重新启动VS但没有成功.

例子:

在这种情况下,名称为ExpandedConverter的类在命名空间clr-namespace:NineGridViewer中"不存在".一个可能的问题可能是我将项目组织到文件夹中,例如转换器都在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>
Run Code Online (Sandbox Code Playgroud)

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;
    }
}
}
Run Code Online (Sandbox Code Playgroud)

Fed*_*gui 10

编译错误阻止构建程序集,因此Visual Studio无法检查它们并在XAML设计器和其他工具中使用它们.

这就是为什么你得到所有这些看似缺失的类错误.

应该有一个"root"错误(通常在列表的底部),这是一个真正的编译错误.如果你修复了所有其他错误应该在构建时消失.