XAML命名空间中不存在的错误

9
这对我来说是个偶发性、经常性的问题。我会随意更改我的项目,然后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>

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;
    }
}
}

6
如果解决方案未构建,则会出现此错误,因为XAML设计器找不到类。只需重新构建即可消除错误。 - Thomas Levesque
1
请检查:https://dev59.com/vGUq5IYBdhLWcg3wPuBQ - Vlad Bezden
在我的情况下,解决方案是删除我的存储库(即所有项目文件),然后再次克隆它。这样,您可以确保即使那些被 Git 忽略的文件也被删除了。 - Emir
1个回答

11

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

这就是为什么您会得到所有这些似乎缺少的类错误。

应该有一个“根”错误(通常在列表底部),它是一个真正的编译错误。如果您修复它,所有其他错误都应该在构建时消失。


这很有道理。在这种情况下,根本错误似乎是我的测试项目中缺少元数据文件,对吗?(错误截图显示了我所有的错误)。 - William Thomas Waller
我清理/重建了我的测试项目,这似乎是根错误的源头。谢谢! - William Thomas Waller

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接