I would like to implement a usercontrol which gets a enumtype via XAML code. Now is the question how do I implement a property which can receive a DataType. What I’ve tried so far is the following:
Code Behind:
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
}
And in XAML I tried this:
…
<Grid>
<local:Test EnumType="{x:Type local:TestEnum}" />
</Grid>
…
The TestEnum:
public enum TestEnum
{
eins,
zwei,
drei
}
But that does not work. It seems that the EnumType property is never set.
Has anyone any idea on how to do that right?
Try
I’m not sure why you were using Type as your property type, just use the TestEnum Type.
Do you get any build errors? I often find that sometimes intellisense fails in the XAML editor until I’ve built the control again, can be a red herring.
EDIT
Apologies, I got the complete wrong end of the stick, I managed to get your code to compile and run, however I don’t get to see the enum type as a valid type in intellisense.