我创建了一个带有Image和Label的自定义ContentView。
我还创建了ImageUrl和LabelText的属性。
我希望此ContentView在列表视图中接收绑定值
<MyCustomContentView ImageUrl="{Binding Image}" LabelText="{Binding Text}" />
但它说没有可绑定属性。如何创建它?
您可以使用此代码并将其粘贴到代码隐藏文件中MyCustomContentView类的构造函数下面。
public static readonly BindableProperty LabelTextProperty = BindableProperty.Create(nameof(LabelText), typeof(string), typeof(MyCustomContentView), default(string));
public static readonly BindableProperty ImageUrlProperty = BindableProperty.Create(nameof(ImageUrl), typeof(string), typeof(MyCustomContentView), default(string));
public string LabelText { get => (string)GetValue(LabelTextProperty); set => SetValue(LabelTextProperty, value); }
public string ImageUrl { get => (string)GetValue(ImageUrlProperty); set => SetValue(ImageUrlProperty, value); }
如果你还有其他困难,请告诉我