我有以下类,我想将它的字典值绑定到数据网格控件
public class DBRow : IEnumerable<DBColumn>
{
public DBColumn this[string ColumnName]
{
get { return Columns[ColumnName]; }
set { Columns[ColumnName] = value; }
}
public Dictionary<string, DBColumn> Columns { get; set; }
public DBRow()
{
this.Columns = new Dictionary<string, DBColumn>();
}
public List<KeyValuePair<string,DBColumn>> GetKeysPair()
{
List<KeyValuePair<string, DBColumn>> ListOfKeyPair = new List<KeyValuePair<string, DBColumn>>();
foreach (var KeyPair in Columns)
{
ListOfKeyPair.Add(KeyPair);
}
return ListOfKeyPair;
}
public void AddColumn(DBColumn Column)
{
Columns.Add(Column.Name, Column);
}
public IEnumerator<DBColumn> GetEnumerator()
{
foreach (var Column in Columns)
{
yield return Column.Value;
}
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
foreach (var item in Columns)
{
yield return item;
}
}
}
在上使用 foreach
GetKeysPair() method
我尝试像这样绑定它:
foreach (var item in Row.GetKeysPair())
{
DataGridTextColumn DataGridColumn = new DataGridTextColumn();
DataGridColumn.Header = item.Value.Name;
DataGridColumn.Binding = new Binding(********); <<--- Problem!!
dataGridDataList.Columns.Add(DataGridColumn); <<--- DataGrid
}
问题是我不知道输入什么
New Binding(string);
我正在尝试绑定以下属性:
public struct DBColumn
{
public object Data { get; set; }
}
我尝试了很多选择,但我无法弄清楚:(