'转换器'是未声明的前缀

时间:2018-04-22 19:36:24

标签: xamarin.forms

我试图按照指南添加转换器到我的页面但是我收到以下错误:

'converters' is an undeclared prefix. Line 8, position 14.

我的页面开头如下:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Historation.Views.NewPartPage"
             xmlns:converter="clr-namespace:App.Converter">
    <ContentPage.Resources>
        <ResourceDictionary>
            <converters:IntEnumConverter x:Key="IntEnum"/> //<- error on this line
        </ResourceDictionary>
    </ContentPage.Resources>

转换器本身如下所示:

namespace App.Converter
{
    public class IntEnumConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is Enum)
            {
                return (int)value;
            }
            return 0;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is int)
            {
                return Enum.ToObject(targetType, value);
            }
            return 0;
        }
    }
}

导致此错误的错误是什么?

1 个答案:

答案 0 :(得分:1)

转换器需要是没有S的转换器,对于在线复制和粘贴错误指南的其他人来说-_-

<converter:IntEnumConverter x:Key="IntEnum"></converter:IntEnumConverter>