views:

205

answers:

1

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.

A: 

You are probably looking for the PropertyValueEditor.

Here's a Walkthrough: Implementing an Inline Value Editor.

chris
I tried it and it works perfectly as advertised for Visual Studio, but not in Blend (Microsoft Expression). I'm still reading related articles to see how to do the same thing in Expression Blend. If you have the answer (you seem to have them all!) let me know, regardless, thanks a bunch for your help. I'm getting closer...
Seb
I don't have much experience with Blend but I would check if the assembly was actually loaded (also move your controls to a separate assembly if you have them in the same project).
chris
This is more complicated than I expected. However, I've found a very solid article about this topic (am going through it right now). Here it is, in case it's useful to anyone:http://blogs.silverlight.net/blogs/justinangel/archive/2008/11/17/silverlight-design-time-extensibility.aspx
Seb