I've created a custom control, and would like to create an attribute (available in Blend's design-time) which would offer a dropdown or combobox. The designer would then select one of the available options. Very much like the "Cursor" combo in the "Common Properties" tab, except that I want full control over what items go in the combo. The choices can vary, so I can't use a hard-coded "enum".
I know it's possible to declare design attributes like this:
protected string mString;
[Category("Common Properties")]
[DisplayName("My Friendly Name")]
public string MyFriendlyName
{
get { return mString; }
set { mString= value; }
}
In the case above, "My Friendly Name" is just a string. The user can enter whatever he wants.
protected Uri mPathname;
[Category("Common Properties")]
[DisplayName("Resource pathname")]
public Uri MyResPathname
{
get { return mPathname; }
set { mPathname = value; }
}
In the case above, "Resource pathname" has a combo box, but the list of items are handled by Blend.
.
If I use an enum, the result is a combo with my items in it, but then I can't change the item-list.
.
public enum MyChoices { Aaa, Bbb }
public class MyButton : Button {
(...)
[Category("Common Properties")]
public MyChoices MyChoice
{
get { return (MyChoices)GetValue(MyChoiceProperty); }
set { SetValue(MyChoiceProperty, value); }
}
public static readonly DependencyProperty MyChoiceProperty =
DependencyProperty.Register("MyChoice",
typeof(MyChoices),
typeof(MyButton ),
new UIPropertyMetadata(
(MyChoices)MyChoices.Aaa,
OnMyChoiceChangedCallback));
}
In the example above, the choices are hard-coded in the enum...
Can anyone help ? I'm sure it's easy, I'm very close but now I'm going in circles.