我有以下用户控件
public partial class TestCtrl : UserControl
{
public enum Alignments
{
HORIZONTAL,
VERTICAL
}
public TestCtrl()
{
InitializeComponent();
}
public static DependencyProperty AlignmentProperty = DependencyProperty.Register(
"Alignment",
typeof(Alignments),
typeof(TestCtrl),
new PropertyMetadata(Alignments.HORIZONTAL));
public Alignments Alignment
{
get
{
return (Alignments)GetValue(AlignmentProperty);
}
set
{
SetValue(AlignmentProperty, value);
}
}
}
该属性有效,但在 xaml 中使用它时,自动完成不会检测该属性的可能值。
找到答案,结果根据这个操作方法,你需要用依赖属性在类之外声明枚举