是否可以绑定Grid.RowProperty
Border bdr = new Border();
bdr.SetValue(Grid.RowProperty, new Binding("RowNo") { Mode = BindingMode.OneWay });
bdr.SetValue(Grid.ColumnProperty, new Binding("ColumnNo") { Mode = BindingMode.OneWay });
在编译时没有错误在运行时产生错误
无法在System.Windows.Data.Binding类型的对象上设置System.Int32类型的DependencyProperty。
答案 0 :(得分:0)
使用SetBinding而非SetValue
。
Border bdr = new Border();
bdr.SetBinding(Grid.RowProperty,
new Binding("RowNo") {
Mode = BindingMode.OneWay
});
bdr.SetBinding(Grid.ColumnProperty,
new Binding("ColumnNo") {
Mode = BindingMode.OneWay
});