【问题标题】:C# Workflow Custom Activity with a string-combobox in the PropertyGrid在 PropertyGrid 中带有字符串组合框的 C# 工作流自定义活动
【发布时间】:2018-07-21 11:57:06
【问题描述】:

我想在 .NET Workflow Foundation 的自定义活动的属性网格中使用字符串组合框。

虽然自定义活动设计器中的组合框工作正常并绑定到活动属性,但属性网格组合框不绑定到活动。

    public class PropertyGridStringComboBox : PropertyValueEditor
{
    public PropertyGridStringComboBox()
    {
        try
        {
            this.InlineEditorTemplate = new DataTemplate();

            FrameworkElementFactory stack = new FrameworkElementFactory(typeof(StackPanel));
            stack.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);

            FrameworkElementFactory comboBox = new FrameworkElementFactory(typeof(ComboBox));

            Binding binding = new Binding()
            {
                Path = new PropertyPath("Config"),
                Mode = BindingMode.TwoWay,
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
            };
            comboBox.SetValue(ComboBox.ItemsSourceProperty, SubnetConfigContainer.GetConfigNames());
            comboBox.SetValue(ComboBox.SelectedValueProperty, binding);
            stack.AppendChild(comboBox);

            this.InlineEditorTemplate.VisualTree = stack;
        }
        catch (Exception ex) { System.Windows.MessageBox.Show(ex.ToString()); }
    }
}

我找到了提示,“FrameworkElementFactory”被标记为已弃用。但是如何正确做呢?

这是对应的活动。

[Designer(typeof(ConfigSelectorActivityDesigner))]
public sealed class ConfigSelectorActivity : ActivityBase
{
    public string Config { get; set; }

    protected override void Execute(CodeActivityContext context)
    {
        SubnetConfigContainer.Instance.SelectedConfig = this.Config;
    }

    static ConfigSelectorActivity()
    {
        AttributeTableBuilder builder = new AttributeTableBuilder();
        builder.AddCustomAttributes(typeof(ConfigSelectorActivity), "Config", new EditorAttribute(typeof(PropertyGridStringComboBox), typeof(PropertyValueEditor)));
        MetadataStore.AddAttributeTable(builder.CreateTable());
    }

    public static void RegisterMetaData(AttributeTableBuilder builder)
    {
        builder.AddCustomAttributes(typeof(ConfigSelectorActivity), new DesignerAttribute(typeof(ConfigSelectorActivityDesigner)));
    }
}

ItemsSource 的类型为List<string>。但是 PropertyGridStringComboBox 中的绑定不起作用。

谁能告诉我如何让它工作或一个工作示例(.NET 4.6.2)。

提前致谢 图卡

【问题讨论】:

    标签: c# workflow-foundation-4 propertygrid


    【解决方案1】:

    我找到了解决方案。

    必须将路径设置为“值”(在“新 PropertyPath”处)。

    Binding binding = new Binding()
            {
                Path = new PropertyPath("Value"),
                Mode = BindingMode.TwoWay,
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
            };
    

    【讨论】:

      猜你喜欢
      • 2012-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      相关资源
      最近更新 更多