繁体   English   中英

C#工作流自定义活动,在PropertyGrid中带有字符串组合框

[英]C# Workflow Custom Activity with a string-combobox in the PropertyGrid

我想在.NET Workflow Foundation中的自定义活动的propertygrid中使用string-combobox。

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

    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)。

在此先感谢Tucca

我找到了解决方案。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM