简体   繁体   English

BindableProperty错误

[英]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. 使用FreshMVVM推送页面模型。

When I remove the BindableProperty BarcodeTypeProperty , the page opens. 当我删除BindableProperty BarcodeTypeProperty ,页面打开。

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: BarcodeType是一个枚举:

public enum BarcodeType
{
    DataMatrix,
    Pdf417
}

Usage in Xaml: 在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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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