【问题标题】:how to create a bindable property in a custom contentView如何在自定义 contentView 中创建可绑定属性
【发布时间】:2019-11-06 04:41:58
【问题描述】:

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

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

我希望这个 ContentView 在列表视图中接收一个绑定值

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

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

【问题讨论】:

标签: xamarin.forms


【解决方案1】:

您可以使用此代码并将其粘贴到代码隐藏文件中 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); }

如果您还有其他困难,请告诉我

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-23
    • 2018-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-20
    • 2011-10-23
    相关资源
    最近更新 更多