在PropertyGrid中带有字符串组合框的C#工作流自定义活动
我想在.NET工作流基础中的自定义活动的属性网格中使用字符串组合框。 虽然自定义活动设计器中的组合框工作正常并绑定到活动属性,但属性网格组合框不绑定到活动在PropertyGrid中带有字符串组合框的C#工作流自定义活动,c#,workflow-foundation-4,propertygrid,C#,Workflow Foundation 4,Propertygrid,我想在.NET工作流基础中的自定义活动的属性网格中使用字符串组合框。 虽然自定义活动设计器中的组合框工作正常并绑定到活动属性,但属性网格组合框不绑定到活动 public class PropertyGridStringComboBox : PropertyValueEditor { public PropertyGridStringComboBox() { try { this.InlineEditorTemplat
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
。但是PropertyGridStringComboBox中的绑定不起作用
任何人都可以告诉我如何让它工作或一个工作的例子(.NET 4.6.2)
提前谢谢
图卡我找到了解决办法
路径必须设置为“Value”(在“newpropertypath”处)
Binding binding = new Binding()
{
Path = new PropertyPath("Value"),
Mode = BindingMode.TwoWay,
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
};