How do you add a dependency property with a discrete set of string values?
Many properties in standard WPF elements support a small discrete set of values that can be specified as strings when the elements are created in XAML. For example, StackPanel's Orientation property supports "Horizontal" and "Vertical" as discrete properties. IntelliSense aids yo开发者_如何学Pythonu by giving you these two options after you open the quotes for the Orientation property. I know a value converter is involved in converting these to enum values of type System.Windows.Controls.Orientation enum.
How do you do this for a custom dependency property for your custom control? I want it to work just as it does for standard element dependency properties with the IntelliSense help and all.
Thanks
If they won't change at run time, the answer is enum
. If they do change, the way I do them is with strings (or objects that implement ToString()
) and converters that fill in the possible values.
Incidentally this is the same way the normal WinForms property grid works.
精彩评论