简体   繁体   中英

BindableProperty error

I have a custom view with some bindable properties. There is something wrong, so when I try to open the page it won't open. I'm not getting an error or output. Using FreshMVVM to push the page model.

When I remove the BindableProperty BarcodeTypeProperty , the page opens.

public class BarcodeView : Image
{
    public static readonly BindableProperty BarcodeValueProperty = BindableProperty.Create(nameof(BarcodeValue), typeof(string), typeof(BarcodeView));
    public string BarcodeValue
    {
        get => (string)GetValue(BarcodeValueProperty);
        set => SetValue(BarcodeValueProperty, value);
    }

    public static readonly BindableProperty BarcodeTypeProperty = BindableProperty.Create(nameof(BarcodeType), typeof(BarcodeType), typeof(BarcodeView));
    public BarcodeType BarcodeType
    {
        get => (BarcodeType)GetValue(BarcodeTypeProperty);
        set => SetValue(BarcodeTypeProperty, value);
    }
}

The BarcodeType is an Enum:

public enum BarcodeType
{
    DataMatrix,
    Pdf417
}

Usage in Xaml:

<view:BarcodeView BarcodeType="{Binding BarcodeType}" BarcodeValue="abcd"/>

尝试给BarcodeTypeProperty一个默认值,因为enum不能为null。

public static readonly BindableProperty BarcodeTypeProperty = BindableProperty.Create("BarcodeType", typeof(BarcodeType), typeof(BarcodeView), BarcodeView.DataMatrix);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM