2011-10-03 128 views
0

在一個循環建立我的WPF的DataGrid列,我要綁定的列寬與下面的代碼成員「我」在我的「WidthList」:如何綁定WPF Datagrid列的width屬性?

var bindingColumnWidth = new Binding(string.Format("WidthList[{0}]", i)); 
customBoundColumn.Width = bindingColumnWidth; 

然而,這給我的錯誤:

無法隱式轉換類型「System.Windows.Data.Binding」到「System.Windows.Controls.DataGridLength」

我怎樣才能解決這個問題?

+0

您可能會發現這篇文章有幫助:WPF的DataGrid:DataGridComboxBox的ItemsSource綁定到的集合集合](http://stackoverflow.com/問題/ 1633800/wpf-datagrid-datagridcomboxbox-itemssource-binding-to-a-collection-of-collection) –

回答

2

DataGridColumn沒有SetBinding方法,你應該試試這個:

BindingOperations.SetBinding(customBoundColumn, DataGridColumn.WidthProperty, bindingColumnWidth); 
+0

謝謝,這看起來很有希望。我無法檢查它,雖然它仍然不起作用。我已經開始了一個新的問題[這裏](http://stackoverflow.com/questions/7639050/binding-the-visibility-property-of-a-wpf-datagrid-column-where-is-my-fault)和我將其標記爲是否/何時起作用的答案。 – Caustix

相關問題