【发布时间】: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