我有两个具有相同行数的 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);
}
关于如何使行具有相同高度的任何想法?
编辑: 问题是我想绑定(bind)单行的行高。 这是它现在的样子: 但我希望 DataGrid2 中的特定行具有 DataGrid1 中另一行的行高。所以例如DataGrid2 中 ID 为 12940 + rm 的行与 DataGrid1 中的行具有相同的高度。
最佳答案
您应该在 XAML 中定义绑定(bind):RowHeight="{Binding ElementName=m_DataGrid1, Path=RowHeight}"
或者如果你真的想在后面的代码中绑定(bind):
m_DataGrid2.SetBinding(DataGrid.RowHeightProperty, new Binding("RowHeight")
{
Source = m_DataGrid1
});
关于c# - 如何绑定(bind)两个 DataGrid 之间的行高?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27502194/