C# Win Forms:如何将DataRepeater中UserControl的属性绑定到集合项本身

C# Win Forms:如何将DataRepeater中UserControl的属性绑定到集合项本身,c#,winforms,data-binding,datarepeater,C#,Winforms,Data Binding,Datarepeater,我正在使用.NET4.0(c#)winforms项目中Visual Basic Power Pack(Microsoft.VisualBasic.PowerPacks.DataRepeater)中的数据转发器。 我正在将它绑定(设置数据源属性)到一个通用的列表。这只是我的一门商务课 我在数据中继器中放置的控件是UserControl。 UserControl有一个名为MyItem的T类型公共属性 我想将UserControl的MyItem属性绑定到集合中类型为T的实际项,但它不起作用。我可以绑定

我正在使用.NET4.0(c#)winforms项目中Visual Basic Power Pack(
Microsoft.VisualBasic.PowerPacks.DataRepeater
)中的数据转发器。 我正在将它绑定(设置
数据源
属性)到一个通用的
列表
。这只是我的一门商务课

我在数据中继器中放置的控件是UserControl。 UserControl有一个名为
MyItem
的T类型公共属性

我想将UserControl的
MyItem
属性绑定到集合中类型为T的实际项,但它不起作用。我可以绑定到T类型的属性之一,但不能绑定到集合项本身。注意,我并没有试图将其绑定到整个集合,而是绑定到数据中继器中与该行一起的集合成员(当前项)

我可以在
数据绑定的
dataMember
参数中键入什么内容。添加
方法以使此工作正常?我尝试了
”、
“/”
,但没有成功

这是我的收藏对象:

public class MyClass
{
  public string SomeProperty {get; set;}

    public MyClass Self
    {
        get
        {
            return this;
        }
        set
        { 

        }
    }

}
这是我的用户控件:

public partial class MyUserControl : UserControl
{


    public MyUserControl()
    {
        InitializeComponent();
    }

    private MyClass _myItem;
    public MyClass MyItem
    {
        get 
        {
            // this never gets called
            return _myItem;
        }
        set {
            // this never gets called
            _myItem = value;
            // Do something with _myItem
        }
    }

    private string _APropertyToBindToOneOfMyItemsProperties;
    public string APropertyToBindToOneOfMyItemsProperties
    {
        get
        {
            // this gets called
            return _APropertyToBindToOneOfMyItemsProperties;
        }
        set
        {
            // this gets called
            _APropertyToBindToOneOfMyItemsProperties = value;
        }
    }
}
这是我在包含数据转发器的控件中的代码, 负责向数据中继器加载数据:

    var MyCollection = new List<MyClass>();
    MyCollection.Add(new MyClass() {SomeProperty = "Value1"});
    MyCollection.Add(new MyClass() {SomeProperty = "Value2"});
    this.MyUserControl1.DataBindings.Add("APropertyToBindToOneOfMyItemsProperties", MyCollection, "SomeProperty"); // this works!
    this.MyUserControl1.DataBindings.Add("MyItem", MyCollection, "/"); // can't get this to work!
    this.MyUserControl1.DataBindings.Add("MyItem", MyCollection, "Self"); // can't get this to work either!

    this.MyDataRepeater.DataSource = MyCollection;
var MyCollection=newlist();
添加(新的MyClass(){SomeProperty=“Value1”});
添加(新的MyClass(){SomeProperty=“Value2”});
this.MyUserControl1.DataBindings.Add(“APropertyToBindToOneOfMyItemsProperties”,MyCollection,“SomeProperty”);//这管用!
this.MyUserControl1.DataBindings.Add(“MyItem”,MyCollection,“/”);//不能让它工作!
this.MyUserControl1.DataBindings.Add(“MyItem”,MyCollection,“Self”);//这也不能用!
this.MyDataRepeater.DataSource=MyCollection;

什么是
查找文档
,我认为
MyCollection
也应该是
MyDataRepeater的
数据源
?使用
数据绑定
,第三个参数应该始终是
属性
,如果没有任何需要的属性,则必须在类中定义属性(其一个实例作为第二个参数传递)第一个。@King King,已更改为MyCollection。抱歉。@King King,我无法使您的工作正常进行。我已编辑了我的问题以包含该问题。