wpf - 指定 DataGrid 单元格跨多列

标签 wpf datagrid

我提到了这个Answer但它不起作用。列仍扩展到行内容。当单元格重新排列时,列大小会以某种方式更新

截图:ColumnSpan Issue

我的自定义DataGridCellsPanel.ArrangeOverride:

protected override Size ArrangeOverride(Size arrangeSize)
{
    var firstCell = Children[0];
    firstCell.SetValue(Panel.HorizontalAlignmentProperty, HorizontalAlignment.Left);
    firstCell.Arrange(new Rect(arrangeSize));

    for (int i = 1; i < Children.Count; i++)
    {
        var remainingCell = Children[i];
        remainingCell.Arrange(new Rect(0,0,0,0));
    }
    return arrangeSize;
}

我的DataGridRow.Template:

<Style x:Key="SpanRowStyle" TargetType="DataGridRow">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type DataGridRow}">
                <Border>
                    <DataGridCellsPresenter Foreground="Black">
                        <DataGridCellsPresenter.ItemsPanel>
                            <ItemsPanelTemplate>
                                <controls:DataGridSpannedCellPanel/>
                            </ItemsPanelTemplate>
                        </DataGridCellsPresenter.ItemsPanel>
                    </DataGridCellsPresenter>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

请帮忙。

最佳答案

发现问题了。 :)

将 ColumnWidth 设置为 Auto 是罪魁祸首。将其设置为静态值效果很好。

关于wpf - 指定 DataGrid 单元格跨多列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31676437/

相关文章:

knockout.js - knockout : working example for editable grid

wpf - 如何将样式绑定(bind)到具有样式元素的任何数据上下文的属性?

wpf - 尝试从另一个线程(wpf,C#)访问对象时发生跨线程异常

c# - 在 Telerik RichText 编辑器中保存和另存为

c# - 我如何才能发现最终用户的用户系统性能设置?

c# - 如何使特定行的 WPF 数据网格单元格只读?

c# - 将 WPF DataGrid 绑定(bind)到 List<Interface>

c# - 解析对象中的路径以提取其中的特定文件夹

WPF StackPanel 垂直框架全高

c# - 密码框不会屏蔽我的密码 WPF