1

我创建了一个自定义控件,并想创建一个属性(在 Blend 的设计时可用),它可以提供下拉列表或组合框。然后设计者将选择可用选项之一。非常类似于“通用属性”选项卡中的“光标”组合,只是我想完全控制组合中的项目。选择可能会有所不同,因此我不能使用硬编码的“枚举”。

我知道可以像这样声明设计属性:

protected string mString;
[Category("Common Properties")]
[DisplayName("My Friendly Name")]
public string MyFriendlyName
{
   get { return mString; }
   set { mString= value; }
}

在上面的例子中,“我的友好名称”只是一个字符串。用户可以输入他想要的任何内容。

protected Uri mPathname;
[Category("Common Properties")]
[DisplayName("Resource pathname")]
public Uri MyResPathname
{
   get { return mPathname; }
   set { mPathname = value; }
}

在上面的例子中,“资源路径名”有一个组合框,但项目列表由 Blend 处理。

如果我使用枚举,结果是其中包含我的项目的组合,但是我无法更改项目列表。

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));

}

在上面的示例中,选择在枚举中被硬编码...

任何人都可以帮忙吗?我确定这很容易,我非常接近,但现在我要绕圈子了。

4

1 回答 1

0

您可能正在寻找 PropertyValueEditor。

这是一个演练:实现内联值编辑器

于 2010-03-24T19:33:36.667 回答