我已从存储库中签出 XAML 应用程序,并正在尝试构建它。我得到了错误:
The tag 'InverseBooleanConverter' does not exist in XML namespace 'clr- ...
Run Code Online (Sandbox Code Playgroud)
我没有使用通用表单应用程序的经验,但发现这InverseBooleanConverter与FreshEssentials包有关。我已经为我当前的项目安装了这个包,但这并没有解决问题。
XAML 的内容:
<UserControl.Resources>
<ResourceDictionary>
<converters:InverseBooleanConverter x:Key="InverseBooleanConverter" />
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Tools.TestTool.Common;component/Styles/ModulesStyle.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
Run Code Online (Sandbox Code Playgroud)
我怎样才能避免这个错误?
此错误意味着您converters在 XAML(例如xmlns:converters="clr-namespace:MeLibrary.Converters)中指定的任何 url都不包含InverseBooleanConverter从IValueConverter.
要解决此问题,只需指出converters项目中正确的命名空间即可。如果您没有任何InverseBooleanConverter类,请创建一个并指向converters新创建的命名空间。
示例转换器:
public class InverseBooleanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
try
{
bool testValue = (bool)value;
return !testValue; // or do whatever you need with this boolean
}
catch { return true; } // or false
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return Convert(value, targetType, parameter, culture);
}
}
Run Code Online (Sandbox Code Playgroud)