添加多个属性的元数据到一个依赖属性的工作流活动 [英] Add multiple Property Metadata to a Dependency Property in a Workflow Activity

查看:163
本文介绍了添加多个属性的元数据到一个依赖属性的工作流活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立了一些在Windows工作流的自定义活动,而我需要添加的DependencyProperty从而可以列表若干该属性值而采用活动时,用户就可以选择。



如真或假。



我知道如何简单地通过使用PropertyMetadata一个默认值,假定我将不得不通过列表/班现在PropertyMetadata?



有没有人已经得到了怎样做一个例子这个吗?



(以下示例代码)

 公共静态的DependencyProperty TestProperty = DependencyProperty.Register(测试,typeof运算(字符串)的typeof(CheckActivity),新PropertyMetadata(真)) ; 
///<总结>
///依赖属性TestProperty'
///< /总结>
[DescriptionAttribute(是否需要真/假条目)]
[的CategoryAttribute(设置)]
[BrowsableAttribute(真)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility。可见)
公共字符串类型
{
得到
{
回报率((字符串)(base.GetValue(CheckActivity.TestProperty)));
}

{
base.SetValue(CheckActivity.TestProperty,值);
}
}


解决方案

第一。所有的真/假的例子也不是很大,在这种情况下使用布尔类型



有关为什么不使用一个枚举一个多值项: -

 公共枚举ItemEnum 
{
首先,
第二,

}

现在在你的活动: -

 公共静态的DependencyProperty TestProperty = DependencyProperty.Register(测试,
typeof运算(ItemEnum)的typeof(测试活动),新PropertyMetadata(ItemEnum.First));

[说明(选择项值)]
[类别(设置)]
[默认值(ItemEnum.First)
公共ItemEnum类型
{
获得
{
回报(ItemEnum)的GetValue(TestActivity.TestProperty);
}

{
的SetValue(TestActivity.TestProperty,值);
}
}

请注意的财产属性的简化。特别是浏览的真实和DesignerSerializationVisiblity是可见的是缺省值,所以删除它们。另外,属性网格是用户,如果默认值被定义为使用更方便。还要注意的放弃了属性后缀,使得它更直接地阅读。


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

解决方案

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.

这篇关于添加多个属性的元数据到一个依赖属性的工作流活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆