将多个属性元数据添加到工作流活动中的依赖属性
我正在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,True/False 示例不太好,在这种情况下使用 bool 类型。
对于多值项,为什么不使用枚举:-
现在在您的活动中:-
请注意属性上属性的简化。特别是 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:-
Now in your Activity:-
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.