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

前端之家收集整理的这篇文章主要介绍了c# – 在WPF中使用enum作为依赖项属性前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我尝试在我的自定义控件中使用枚举类型作为依赖项属性,但始终会收到错误
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

猜你在找的C#相关文章