【问题标题】:How can I bind the rowheight between two DataGrids?如何绑定两个 DataGrid 之间的 rowheight?
【发布时间】: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


    【解决方案1】:

    您应该在 XAML 中定义绑定:RowHeight="{Binding ElementName=m_DataGrid1, Path=RowHeight}"

    或者如果你真的想在后面的代码中绑定:

     m_DataGrid2.SetBinding(DataGrid.RowHeightProperty, new Binding("RowHeight")
                {
                    Source = m_DataGrid1
                });
    

    【讨论】:

    • 感谢您的回答。但我正在寻找其他东西,请参阅上面的编辑
    猜你喜欢
    • 2011-05-12
    • 2011-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-14
    • 1970-01-01
    • 2021-03-23
    相关资源
    最近更新 更多