tags:

views:

37

answers:

1

In my WPF project I have a custom control with some properties assigned, they are of "string" and "bool" types. Something like:

public class CustControl : Control
{
    static CustControl()
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(CustControl), new FrameworkPropertyMetadata(typeof(CustControl)));

    }

    public readonly static DependencyProperty CustNoProperty = DependencyProperty.Register("CustNo", typeof(string), typeof(CustControl), new PropertyMetadata(""));

    public string CustNo
    {
        get { return (string)GetValue(CustNoProperty); }
        set { SetValue(CustNoProperty, value); }
    }

    public readonly static DependencyProperty IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(CustControl), new PropertyMetadata(false));

    public bool IsSelected
    {
        get { return (bool)GetValue(IsSelectedProperty); }
        set { SetValue(IsSelectedProperty, value); }
    }
....
}

Now I have to add here a property for choosing a string value from a predefined set of values, let's say, "Red", "Green", "Yellow", "Black".

What is the correct way to do this?

+1  A: 

If your predefined strings are as simple as in the example, then how about using an enum as that property's type? The string value may be easily obtained by calling ToString() on the enum value.

Pawel Marciniak