我在用户控件中创建BindableProperty时遇到问题。我的用户控件是一个ResultLabel类。这是我的代码,我在其中创建BindableProperty:
public static readonly BindableProperty StateProperty = BindableProperty.Create(nameof(State), typeof(ResultStateEnum), typeof(ResultLabel));此BindableProperty应该接受枚举(ResultStateEnum),但它抛出了TypeInitializationException。
发布于 2018-08-21 15:42:50
问题是没有传递给该方法的默认值参数。这是一个可选参数,因此程序将尝试将null作为默认参数传递。枚举不能为空,因此将触发异常。您应该向Create方法中再添加一个参数。假设ResultStateEnum的值为ResultStateEnum.Default。那么你的代码应该是这样的:
public static readonly BindableProperty StateProperty = BindableProperty.Create(nameof(State), typeof(ResultStateEnum), typeof(ResultLabel), ResultStateEnum.Default); https://stackoverflow.com/questions/51943885
复制相似问题