No property, bindable property, or event found for 'Converter', or mismatching type between value and property.
There is my code:
<StackLayout Grid.Row="0" Style="{StaticResource GridStyleSection}" Orientation="Vertical">
<controls:LabelItem LeftText="姓名:" RightText="{Binding Model.FullName}"></controls:LabelItem>
<controls:Separator Style="{StaticResource ControlStyleSeparator}"></controls:Separator>
<controls:LabelItem LeftText="性别:" RightText="{Binding Model.Sex,Converter={Binding SexConverter}}"></controls:LabelItem>
<controls:Separator Style="{StaticResource ControlStyleSeparator}"></controls:Separator>
<controls:LabelItem LeftText="阳历生日:" RightText="1981-05-15"></controls:LabelItem>
<controls:Separator Style="{StaticResource ControlStyleSeparator}"></controls:Separator>
<controls:LabelItem LeftText="农历生日:" RightText="一九八一年五月十二日"></controls:LabelItem>
<controls:Separator Style="{StaticResource ControlStyleSeparator}"></controls:Separator>
<controls:LabelItem LeftText="星座:" RightText="金牛座"></controls:LabelItem>
<controls:Separator Style="{StaticResource ControlStyleSeparator}"></controls:Separator>
<controls:LabelItem LeftText="生肖:" RightText="鸡"></controls:LabelItem>
<controls:Separator Style="{StaticResource ControlStyleSeparator}"></controls:Separator>
<controls:LabelItem LeftText="身份证号码:" RightText="350825198105051611"></controls:LabelItem>
<controls:Separator Style="{StaticResource ControlStyleSeparator}"></controls:Separator>
<controls:LabelItem LeftText="身份证有效期:" RightText="2009-02-11 至 2029-02-11"></controls:LabelItem>
</StackLayout>
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:
/// <summary>
/// 格式化性别
/// </summary>
public class SexConverter : IValueConverter
{
/// <summary>
/// 在绑定模式为OneWay或TwoWay时,数据由源流向目标时调用,
/// </summary>
/// <param name="value"></param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns></returns>
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.
thanks