我尝试在自定义控件中使用枚举类型作为依赖项属性,但始终会出错:
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); }
}
拜托,看。错误在哪里?
答案 0 :(得分:11)
您的DP未在类的范围内声明。 DP声明后看起来你有一个额外的闭合支撑。
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