如何在自定义contentView中创建可绑定属性 [英] how to create a bindable property in a custom contentView

查看:76
本文介绍了如何在自定义contentView中创建可绑定属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个带有图像和标签的自定义ContentView.

I created a custom ContentView with a Image and a Label.

我还创建了ImageUrl和LabelText的属性.

I also created a property of ImageUrl and LabelText.

我希望此ContentView在列表视图中接收绑定值

I want this ContentView an receive a Binding value in a listview

<MyCustomContentView ImageUrl="{Binding Image}" LabelText="{Binding Text}" />

但是它说没有可绑定的属性.如何创建它?

but it says there is no bindable property.how to create it?

推荐答案

您可以使用此代码并将其粘贴到文件后面的代码中MyCustomContentView类的构造函数下方.

You can use this code and paste it below the constructor of the MyCustomContentView class in the code behind file.

        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); }

让我知道您是否还有其他困难

Let me know if you have further difficulties

这篇关于如何在自定义contentView中创建可绑定属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆