名稱的列當我有一個簡單的DataSet
具有與簡單的列名(即沒有空格或週期),碼錶,如以下工作就好:不能WPF DataGrid綁定到表與具有空間和其他特殊字符
DataGrid resultsGrid=...; // Actually defined in the XAML
DataSet ds=...; // The is the DataSet that contains one table
Binding binding = new Binding();
resultsGrid.DataContext=ds.Tables[0];
resultsGrid.SetBinding(DataGrid.ItemsSourceProperty, binding);
數據網格在上面的例子有AutoGenerateColumns
屬性設置爲True
和正確地從在DataSet
表填充其數據。
但是,如果我的表中有包含空格/時間或其它特殊字符名稱的列,自動綁定似乎失敗。我得到的錯誤,如:
System.Windows.Data信息:20:BindingExpression不能 由於缺少信息檢索值。 BindingExpression:Path = My Col. Name; DataItem ='DataRowView'(HashCode = 8146871);目標元素 是'TextBlock'(Name ='');目標屬性是「文本」(類型「字符串」)
顯然,自動生成的綁定表達式Path=My Col. Name
無效。整個路徑需要「引用」以便允許空格和句點。對於列名更復雜的表,是否有任何方法可以使用AutoGeneratedColumns
?還是我現在必須全部手動?
這正是我現在要做的,在將它綁定到網格之前重命名DataSet中的列 - 黑客攻擊。 – 2012-01-30 22:18:52