【发布时间】:2012-02-29 09:41:40
【问题描述】:
我想实现一个通过 XAML 代码获取枚举类型的用户控件。现在的问题是如何实现可以接收 DataType 的属性。到目前为止,我尝试过的如下:
代码背后:
public partial class Test : UserControl, INotifyPropertyChanged
{
#region DependencyProperty: EnumType
public Type EnumType
{
get
{
return (Type)GetValue(EnumTypeProperty);
}
set
{
SetValue(EnumTypeProperty, value);
}
}
public static readonly DependencyProperty EnumTypeProperty =
DependencyProperty.Register("EnumType", typeof(Type), typeof(Test),
new FrameworkPropertyMetadata());
#endregion
}
在 XAML 中我尝试了这个:
...
<Grid>
<local:Test EnumType="{x:Type local:TestEnum}" />
</Grid>
...
TestEnum:
public enum TestEnum
{
eins,
zwei,
drei
}
但这不起作用。似乎从未设置 EnumType 属性。
有没有人知道如何正确地做到这一点?
【问题讨论】:
标签: wpf user-controls properties