开发者

Using enum as a dependency property in WPF

开发者 https://www.devze.com 2022-12-13 14:33 出处:网络
I try to use enum type as a dependency property in my custom control, but always get an error: public enum PriceCategories

I try to use enum type as a dependency property in my custom control, but always get an error:

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 PriceCatego开发者_StackOverflowries PriceCat  // here I get an error "Expected class, delegate, enum, interface or struct"
    {
        get { return (PriceCategories)GetValue(PriceCatProperty); }
        set { SetValue(PriceCatProperty, value); }
    }

Please, look. Where is mistake?


Your DP is not being declared within the scope of a class. It looks like you have an extra closing brace after the DP declaration.

public enum PriceCategories
{
  // ...
}
public static readonly DependencyProperty PriceCatProperty =
  DependencyProperty.Register("PriceCat", typeof(PriceCategories),
  typeof(CustControl),  new PropertyMetadata(PriceCategories.First));
};  // <-- this is probably closing the containing class
0

精彩评论

暂无评论...
验证码 换一张
取 消