【发布时间】:2015-02-14 14:53:17
【问题描述】:
我有两个行数相同的 DataGrid。但可能是 DataGrid1 中的一行包含更多文本,并且行高会比 DataGrid2 中的大。我已经尝试过这样的事情:
for (int i = 0; i < DataGrid1.Items.Count; i++)
{
DataGrid1.ScrollIntoView(DataGrid1.Items[i]);
DataGridRow row = (DataGridRow)DataGrid1.ItemContainerGenerator.ContainerFromIndex(i);
Binding bindingHeight = new Binding();
bindingHeight.Mode = BindingMode.TwoWay;
bindingHeight.Source = row.ActualHeight;
bindingHeight.Path = new PropertyPath(DataGridRow.HeightProperty);
DataGrid2.ScrollIntoView(DataGrid2.Items[i]);
DataGridRow row2 = (DataGridRow)DataGrid2.ItemContainerGenerator.ContainerFromIndex(i);
BindingOperations.SetBinding(row2, DataGridRow.HeightProperty, bindingHeight);
}
任何想法如何让行具有相同的高度?
编辑: 问题是我想绑定单行的行高。 这是它目前的样子: 但我希望 DataGrid2 中的特定行具有 DataGrid1 中另一行的行高。所以例如DataGrid2 中 ID 为 12940 + rm 的行与 DataGrid1 中的行高度相同。
【问题讨论】:
标签: c# wpf binding datagrid row