0

First, look at the width of the last column. It is "*".

Here's the xaml to reproduce the problem:

<Window x:Class="DataGridStaredColumnTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:System="clr-namespace:System;assembly=mscorlib" Title="MainWindow" Height="350" Width="525">
    <Grid>
        <ScrollViewer HorizontalScrollBarVisibility="Auto">
            <Grid MinWidth="200" HorizontalAlignment="Stretch">
                <DataGrid AutoGenerateColumns="False" HorizontalAlignment="Stretch">
                    <DataGrid.Columns>
                        <DataGridTemplateColumn Header="1" Width="Auto">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Text="Column1" Background="Green"/>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>

                        <DataGridTemplateColumn Header="2" Width="*">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBox Text="Column2" Background="Yellow" HorizontalAlignment="Stretch"/>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                    </DataGrid.Columns>

                    <DataGrid.Items>
                        <System:Int16>1</System:Int16>
                        <System:Int16>2</System:Int16>
                        <System:Int16>3</System:Int16>
                    </DataGrid.Items>
                </DataGrid>
            </Grid>
        </ScrollViewer>
    </Grid>
</Window> 

There's definitely some poblem with the scrollviewer here cause everything works fine if HorizontalScrollbar is disabled.

I found this post concernign the problem. Nevertheless the solution contains another bug of evergrowing Border after window is enlareged.

Does anybody have an idea how to kill this extra column?

5
  • Why would you put a DataGrid in a ScrollViewer when DataGrid has scrolling itself?
    – paparazzo
    Sep 26, 2012 at 13:04
  • As you can see DataGrid is inside Grid. It is not the only control on the are to be scrollable. Sep 26, 2012 at 13:23
  • Yes I can see your code. That inner Grid is not constrained. You have a scroll in a scroll. That negates the inner scroll.
    – paparazzo
    Sep 26, 2012 at 14:23
  • Well, the Grid inside the SV is stretched untill its minimum width. DataGrid is also stretched. Even If I disable scrolling inside the DataGrid extra column stays. I suspect SV to set infinite available size for its child on Measure call. But wouldn't it be more reasonable to make a two step measure? First, we try to calculate the size with the constraint and only if desired element's size exceeds the offered constraint we repeat the measure with no constraints. Sep 26, 2012 at 15:12
  • What you expect is not material.
    – paparazzo
    Sep 26, 2012 at 16:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.