将多个属性元数据添加到工作流活动中的依赖属性

发布于 2024-08-11 09:42:19 字数 915 浏览 4 评论 0原文

我正在 Windows 工作流中构建多个自定义活动,并且需要添加一个 DependencyProperty,它可以列出该属性的多个值,然后用户可以在使用该活动时选择这些值。

例如,对或错。

我知道如何使用 PropertyMetadata 简单地传递默认值,并且假设我现在必须传递一个列表/类 PropertyMetadata?

有人已经有如何执行此操作的示例吗?

(下面的示例代码)

public static DependencyProperty TestProperty = DependencyProperty.Register("Test", typeof(string), typeof(CheckActivity), new PropertyMetadata("True"));
/// <summary>
/// Dependency property for 'TestProperty'
/// </summary>   
[DescriptionAttribute("Whether a True/False entry is required")]
[CategoryAttribute("Settings")]
[BrowsableAttribute(true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
public string Type
{
    get
    {
        return ((string)(base.GetValue(CheckActivity.TestProperty)));
    }
    set
    {
        base.SetValue(CheckActivity.TestProperty, value);
    }
}

I am building a number of Custom Activities in Windows Workflow and I need to add a DependencyProperty which can list a number of values for that property which the user can then select when using the activity.

e.g. True or False.

I know how to simply pass a default using the PropertyMetadata, and presume that I will have to pass a list/class now the PropertyMetadata?

Has anyone already got an example of how to do this please?

(Example Code below)

public static DependencyProperty TestProperty = DependencyProperty.Register("Test", typeof(string), typeof(CheckActivity), new PropertyMetadata("True"));
/// <summary>
/// Dependency property for 'TestProperty'
/// </summary>   
[DescriptionAttribute("Whether a True/False entry is required")]
[CategoryAttribute("Settings")]
[BrowsableAttribute(true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
public string Type
{
    get
    {
        return ((string)(base.GetValue(CheckActivity.TestProperty)));
    }
    set
    {
        base.SetValue(CheckActivity.TestProperty, value);
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扛起拖把扫天下 2024-08-18 09:42:19

首先,True/False 示例不太好,在这种情况下使用 bool 类型。

对于多值项,为什么不使用枚举:-

 public enum ItemEnum
 {
    First,
    Second,
    Third
 }

现在在您的活动中:-

 public static DependencyProperty TestProperty = DependencyProperty.Register("Test",  
   typeof(ItemEnum), typeof(TestActivity), new PropertyMetadata(ItemEnum.First));

[Description("Select Item value")]
[Category("Settings")]
[DefaultValue(ItemEnum.First)]
public ItemEnum Type
{
  get
  {
    return (ItemEnum)GetValue(TestActivity.TestProperty);
  }
  set
  {
    SetValue(TestActivity.TestProperty, value);
  }
}

请注意属性上属性的简化。特别是 Browseable 为 true 和 DesignerSerializationVisibity 为 Visible 是默认设置,因此请删除它们。此外,如果定义了 DefaultValue,则“用户”更容易使用属性网格。注意还删除了“属性”后缀,使其更易于阅读。

First of all the True/False example isn't great, in that case use a bool type.

For a multi-value item why not use an Enum:-

 public enum ItemEnum
 {
    First,
    Second,
    Third
 }

Now in your Activity:-

 public static DependencyProperty TestProperty = DependencyProperty.Register("Test",  
   typeof(ItemEnum), typeof(TestActivity), new PropertyMetadata(ItemEnum.First));

[Description("Select Item value")]
[Category("Settings")]
[DefaultValue(ItemEnum.First)]
public ItemEnum Type
{
  get
  {
    return (ItemEnum)GetValue(TestActivity.TestProperty);
  }
  set
  {
    SetValue(TestActivity.TestProperty, value);
  }
}

Note the simplification of the Attributes on the property. In particular Browseable being true and DesignerSerializationVisiblity being Visible are defaults so remove them. Also the property grid is easier for the "user" to use if the DefaultValue is defined. Note also dropped the "Attribute" suffix, makes it much more straightforward to read.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文