c# - XAML 命名空间上的 "does not exist in namespace"错误

标签 c# wpf visual-studio xaml visual-studio-2012

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

我已经多次清理、构建和重建,以及重新启动 VS 都没有成功。

示例:

在这种情况下,它是在命名空间 clr-namespace:NineGridViewer 中“不存在”的类 ExpandedConverter。一个可能的问题可能是我将我的项目组织到文件夹中,例如转换器都在 IValueConverters 文件夹中,而 MainWindow 在 Views 文件夹中。但是命名空间没有改变

enter image description here enter image description here

<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/

相关文章:

visual-studio - 如何解决... Visual Studio 源代码管理通知 "Projects have recently been added to this solution"

c# - 如果为 null 或为空,则不插入字段

c# - 状态 500 : InvalidOperationException: No route matches the supplied values

c# - 如何去除 Visual Studio 2017 15.8 版中的水平白线?

wpf - 有没有办法转换用作 ItemsSource 的集合的成员?

wpf - 绑定(bind)另一个元素的可见性 - 并反转

c# - 错误 : Items collection must be empty before using ItemsSource

c# - 保留共享资源(例如 json 文件)可用于具有完整路径的测试

javascript - 在asp.net c#中通过POST传递动态列表

wpf - 如何通过两个 View 模型传递对象? Wpf MVVM