弃用约束力,这是什么新方法



这种绑定被弃用,您不应该再使用仿制药了。我应该做什么?

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

您将类型定义为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);
    });

这是我在自定义渲染器中拥有属性的方式,不应将其弃用

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

最新更新