这对我来说是个偶发性、经常性的问题。我会随意更改我的项目,然后VisualStudio就会给我96个命名空间错误。它们几乎总是针对我的XAML命名空间声明的错误,但我知道这些类存在于该命名空间中。
我已经尝试过清理和构建、多次重建以及重启VS等方法,但都没有成功。
例如,在这种情况下,ExpandedConverter类在命名空间clr-namespace:NineGridViewer中“不存在”。一个可能的问题是,我将项目组织成文件夹,例如转换器都在IValueConverters文件夹中,而MainWindow则在Views文件夹中。但是命名空间并没有改变。
(图片已保留,无需翻译)
我已经尝试过清理和构建、多次重建以及重启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;
}
}
}