【问题标题】:How do I bind the width property of a WPF Datagrid column?如何绑定 WPF Datagrid 列的宽度属性?
【发布时间】:2011-11-29 16:20:45
【问题描述】:

在设置我的 WPF DataGrid 列的循环中,我想使用以下代码将列宽绑定到我的“WidthList”中的成员“i”:

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

但是,这给了我错误:

无法将类型“System.Windows.Data.Binding”隐式转换为“System.Windows.Controls.DataGridLength”

我该如何解决这个问题?

【问题讨论】:

标签: wpf binding datagrid width


【解决方案1】:

DataGridColumn 没有SetBinding 方法,你应该试试这个:

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

【讨论】:

  • 谢谢,这看起来很有希望。我无法在我的情况下检查它,因为它仍然无法正常工作。我已经提出了一个新问题here,如果/当一切正常时,我会将其标记为答案。
猜你喜欢
  • 2017-08-07
  • 1970-01-01
  • 1970-01-01
  • 2015-03-20
  • 1970-01-01
  • 2014-10-05
  • 1970-01-01
  • 2011-10-17
  • 1970-01-01
相关资源
最近更新 更多