弃用的绑定,有什么新的方法呢?

时间:2018-02-07 13:36:31

标签: c# xamarin xamarin.forms

此约束已弃用,您不应再使用泛型。我该怎么做呢?

BindableProperty.Create<ImageGallery, IList>(
                view => view.ItemsSource,
                default(IList),
                BindingMode.TwoWay,
                propertyChanging: (bindableObject, oldValue, newValue) => {
                    ((ImageGallery)bindableObject).ItemsSourceChanging();
                },
                propertyChanged: (bindableObject, oldValue, newValue) => {
                    ((ImageGallery)bindableObject).ItemsSourceChanged(bindableObject, oldValue, newValue);
                }
            );

2 个答案:

答案 0 :(得分:5)

您可以将类型定义为Create()方法的参数,如下所示:

public ImageGallery MyImageGallery
{
    get { return (ImageGallery)GetValue(MyImageGalleryProperty); }
    set { SetValue(MyImageGalleryProperty, value); }
}

public static BindableProperty MyImageGalleryProperty = BindableProperty.Create(nameof(MyImageGallery), typeof(ImageGallery), typeof(IList), default(IList), BindingMode.TwoWay,
    propertyChanging: (bindableObject, oldValue, newValue) => 
    {
        ((ImageGallery) bindableObject).ItemsSourceChanging();
    },
    propertyChanged: (bindableObject, oldValue, newValue) => 
    {
        ((ImageGallery) bindableObject).ItemsSourceChanged(bindableObject, oldValue, newValue);
    });

答案 1 :(得分:0)

以下是我在自定义渲染器中拥有属性的方法,不应弃用

public static readonly BindableProperty SearchTextProperty =
    BindableProperty.Create(nameof(SearchText), typeof(string), typeof(MyCustomClass), string.Empty);

public string SearchText
{
    get { return (string)GetValue(SearchTextProperty); }
    set { SetValue(SearchTextProperty, value); }
}