gpt4 book ai didi

c# - 将多个属性元数据添加到工作流事件中的依赖属性

转载 作者:太空宇宙 更新时间:2023-11-03 14:34:08 28 4
gpt4 key购买 nike

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

最佳答案

首先,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 且 DesignerSerializationVisiblity 为 Visible 是默认设置,因此请删除它们。如果定义了 DefaultValue,“用户”也更容易使用属性网格。注意还删除了“属性”后缀,使其更易于阅读。

关于c# - 将多个属性元数据添加到工作流事件中的依赖属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1728356/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com