加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 在WPF中使用enum作为依赖项属性

发布时间:2020-12-15 08:24:12 所属栏目:百科 来源:网络整理
导读:我尝试在我的自定义控件中使用枚举类型作为依赖项属性,但始终会收到错误: public enum PriceCategories { First = 1,Second = 2,Third = 3,Fourth = 4,Fifth = 5,Sixth = 6 } public static readonly DependencyProperty PriceCatProperty =DependencyPrope
我尝试在我的自定义控件中使用枚举类型作为依赖项属性,但始终会收到错误:
public enum PriceCategories
    {
        First = 1,Second = 2,Third = 3,Fourth = 4,Fifth = 5,Sixth = 6
    }
    public static readonly DependencyProperty PriceCatProperty =
DependencyProperty.Register("PriceCat",typeof(PriceCategories),typeof(CustControl),new PropertyMetadata(PriceCategories.First));
};

    public PriceCategories PriceCat  // here I get an error "Expected class,delegate,enum,interface or struct"
    {
        get { return (PriceCategories)GetValue(PriceCatProperty); }
        set { SetValue(PriceCatProperty,value); }
    }

敬请期待.哪里出错?

解决方法

您的DP未在类的范围内声明.在DP声明之后看起来你有一个额外的右大括号.
public enum PriceCategories
{
  // ...
}
public static readonly DependencyProperty PriceCatProperty =
  DependencyProperty.Register("PriceCat",new PropertyMetadata(PriceCategories.First));
};  // <-- this is probably closing the containing class

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读