WPF Designer Custom Properties - Drop-down List

I would like to have a dropdown for a custom property in User Control in WPF. Everything works fine when I use Enum as a property:

/// <summary>
/// Interaction logic for Sample.xaml
/// </summary>
public partial class Sample : System.Windows.Controls.UserControl
{
    public Sample()
    {
        InitializeComponent();
    }

    [DefaultValue(Letters.A)]
    [Browsable(true)]
    [Category("ControlDisplay")]
    [Description("Letter")]
    public Letters Letter { get; set; }


    public enum Letters
    {
        A,
        B,
        C,
        D
    }
}

enter image description here

Awesome :).

But I want to achieve this for a custom class or even a string. How should I do it?

Thanks in advance.

0
source share
1 answer

Finally got anwser (after digging up some documentation - a lot of that). First of all, there is an attribute Type Converter that a pleasant walk, how to implement it, here . This is what led me to this.

: GetStandardValuesSupported(ITypeDescriptorContext context), true GetStandardValues(ITypeDescriptorContext context), StandardValuesCollection . , :

    [TypeConverter(typeof(MyClassConverter))]
    public MyClass MyProperty { get; set; }

.

0

All Articles