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

Jso*_*ork 1 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);
                }
            );
Run Code Online (Sandbox Code Playgroud)

Den*_*öer 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);
    });
Run Code Online (Sandbox Code Playgroud)