1

我是 .NET 4 的新手,我正在寻找一种方法来设计一个接受某种类型列表的自定义活动(在我的示例中FormInput)。因此,此活动的每个实例都可以拥有自己的 FormInput 私有列表。

这个代码片段来自活动设计器,我试图这样做,但由于某种原因,它不起作用。在工作流中使用我的活动时,数据网格被禁用。

<Grid>...
   <DataGrid AutomationProperties.AutomationId="InputElements" 
      ItemsSource="{Binding Path=ModelItem.InputElements}" CanUserAddRows="True"
      CanUserDeleteRows="True"></DataGrid>
...
</Grid>

这是应该保存列表的自定义 Activity 类的属性。

public ObservableCollection<FormInput> InputElements

任何帮助表示赞赏。

4

2 回答 2

1

我明白了,认为问题在于绑定到不可枚举的对象。

直接绑定到ModelItem属性值解决了这个问题

public partial class ActivityDesigner1
{
    public ObservableCollection<FormInput> MyProperty
    {
        get { return (ObservableCollection<FormInput>)ModelItem.Properties["InputElements"].ComputedValue; }
    }
}

在设计师中:<DataGrid ItemsSource="{Binding Path=MyProperty}"...

你应该能够使用ValueConverter来做到这一点

按照这个链接解决添加第一项的问题

哦,别忘了初始化你的 ObservableCollection

于 2011-12-01T02:32:10.863 回答
0

检查DataContextofDataGrid是否设置正确并使用代码片段进行收集:

private ObservableCollection<FormInput> inputElements;

public ObservableCollection<FormInput> InputElements
{
    get
    {
        if (this.inputElements == null)
        {
            this.inputElements = new ObservableCollection<FormInput>();
        }

        return this.inputElements;
    }
}
于 2011-11-24T07:01:23.627 回答