将转换器导入XAML时Xamarin抛出错误

时间:2019-06-13 20:19:02

标签: xamarin xamarin.forms .net-core

我有一个xaml文件,我在其中导入转换器,但是当我尝试编译时 Visual Studio引发异常,并显示消息“无法解析程序集:'X'”。该转换器在同一个项目中,我从同一个项目中导入了一个行为,并且运行良好。我不知道我做错了什么,还是xamarin或Visual Studio的问题。

这是我的转换器

namespace YogaMobileApp.Converters
{
    public class BoolNegation:IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (targetType != typeof(bool))
                throw new InvalidOperationException("The target must be a boolean");

            return !(bool)value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (targetType != typeof(bool))
                throw new InvalidOperationException("The target must be a boolean");

            return !(bool)value;
        }
    }
}

在我的Xaml中

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:converters="clr-namespace:YogaMobileApp.Converters"
             mc:Ignorable="d"
             x:Class="YogaMobileApp.Views.LoginPage"
             d:BackgroundColor="White"
             NavigationPage.HasNavigationBar="False"
             BackgroundColor="White">
    <ContentPage.Resources>
        <ResourceDictionary>
            <converters:BoolNegation x:Name="negation" />
        </ResourceDictionary>
    </ContentPage.Resources>

 ...
</ContentPage>

///

When I try to compile vs throw an error "Failed to resolve assembly: 'YogaMobileApp' "

1 个答案:

答案 0 :(得分:0)

此行似乎是错误的,可能导致此类错误,应该是:

<converters:BoolNegation x:Key="negation" />