Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make specific of DataGrid cell span multiple columns

Tags:

wpf

datagrid

I referred this Answer but Its not working. Column still expands to the Row content. Column size is somehow gets updated when cell is re-arranged

Screenshot: ColumnSpan Issue

My custom 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;
}

My 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>

Please help.

like image 634
deathrace Avatar asked Jul 28 '15 12:07

deathrace


1 Answers

Found the issue. :)

Setting ColumnWidth to Auto was the culprit. setting it to static values worked fine.

like image 117
deathrace Avatar answered Nov 06 '22 04:11

deathrace