我尝试在自定义控件中使用枚举类型作为依赖属性,但总是收到错误:
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", typeof(PriceCategories),
typeof(CustControl), new PropertyMetadata(PriceCategories.First));
}; // <-- this is probably closing the containing class
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)