为什么某些可绑定属性无效?

时间:2019-11-09 10:42:05

标签: xamarin.forms

我创建了可绑定属性,但是其中一个找不到,而其他都可以正常工作。

public string Username { get => (string)GetValue(UserNameProperty); set => SetValue(UserNameProperty, value); }
public static readonly BindableProperty UserNameProperty = BindableProperty.Create(nameof(LiveView.Username), typeof(string), typeof(LiveView), null);

它告诉我找不到“用户名”的属性,可绑定属性或事件,或者值和属性之间的类型不匹配。

这是一个错误的陈述吗?

但是当三个语句都使用正确的方法时,另一个名为Title和UserImage的属性就可以了。

1 个答案:

答案 0 :(得分:1)

请使用以下声明。

公共字符串UserName {get =>(string)GetValue(UserNameProperty); set => SetValue(UserNameProperty,value); }

注意:尝试声明与BindableProperty前缀语句相同的CLR属性名。