Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

No property, bindable property, or event found for 'Converter', or mismatching type between

$
0
0

No property, bindable property, or event found for 'Converter', or mismatching type between value and property.

There is my code:


and controls:LabelIem code:

    #region RightText:右文字
    public static readonly BindableProperty RightTextProperty = BindableProperty.Create(nameof(RightText), typeof(string), typeof(LabelItem), null, propertyChanged: OnRightTextChanged);

    private static void OnRightTextChanged(BindableObject bindable, object oldValue, object newValue)
    {
        string text = newValue as string;
        var label = (LabelItem)bindable;
        label.LabelRight.Text = text;
    }

    public string RightText
    {
        get { return (string)GetValue(RightTextProperty); }
        set { SetValue(RightTextProperty, value); }
    }
    #endregion

then SexConverter definition:
///


/// 格式化性别
///

public class SexConverter : IValueConverter
{
///
/// 在绑定模式为OneWay或TwoWay时,数据由源流向目标时调用,
///

///


///
///
///
///
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!(value is int?))
{
throw new InvalidNavigationException("The target must be a boolean");
}
        return ((int)value == 1) ? "男" : "女";
    }

    /// <summary>
    /// 在绑定模式为TwoWay或OneWayToSource时数据由目标流向源时调用
    /// </summary>
    /// <param name="value"></param>
    /// <param name="targetType"></param>
    /// <param name="parameter"></param>
    /// <param name="culture"></param>
    /// <returns></returns>
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return null;
    }
}

Why compile is wrong??::
No property, bindable property, or event found for 'Converter', or mismatching type between value and property.

The error occurred:
RightText="{Binding Model.Sex,Converter={Binding SexConverter}}"

thanks


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>