Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the last DataGrid's column occupy the whole left space?

First! I know it can seem a kind of dup nevertheless it isn't.

I have a grid as a data template for DataGrid.RowDetails. It has three columns: two with Width="Auto" and the 3d with Width="*"

<DataTemplate x:Key="NotEmptyDistributionsTemplateKey">
    <DataGrid ItemsSource="{Binding SoftwareVersionDistributions}"
        CanUserAddRows="False"
        CanUserDeleteRows="False"
        CanUserReorderColumns="False"
        CanUserResizeColumns="True"
        CanUserSortColumns="False"
        IsReadOnly="True"
        CanUserResizeRows="False"
        AutoGenerateColumns="False"
        RowHeaderWidth="0"
        Margin="20,5"
        HorizontalAlignment="Stretch">
        <DataGrid.Columns>
            <DataGridTextColumn 
                Header="Architecture" 
                Binding="{Binding SoftwareArchitecture.Name, TargetNullValue=Все, FallbackValue=Все}"
                Width="Auto"/>
            <DataGridTextColumn 
                Header="Language" 
                Binding="{Binding SysCodepage.Title, TargetNullValue=Все, FallbackValue=Все}" 
                Width="Auto"/>
            <DataGridHyperlinkColumn 
                Header="Link" 
                Binding="{Binding DownloadLink}"
                Width="*" 
                CanUserResize="False"/>
        </DataGrid.Columns>
    </DataGrid>
</DataTemplate>

This template shows exactly 3 columns, if Grid is nested in a cell. But when it is used as RowDetaislTemplate 4th empty column appears. This makes me mad.

Does anybody have ideas why this can happen?

Update 1. How it looks:

enter image description here

Update 2.

Finally I found the soultion. Just added ScrollViewer.HorizontalScrollBarVisibility="Disabled"

Now it's ok:

enter image description here

But I cannot understand this odd behavior.

Update 3 (may be helpful to someone)

Recently we've found a bug which our users had and the developers did not. The bug was again about DataGrid's width and alignment. Well, may be this was not really a bug, but we had different behavior of the control.
The research revealed that when installing .net framework 4.5 installer also updated .net framework 4.0. This update changed somehow DataGrid's behavior. (to the expected one)
We asked our users to install framework 4.5 and the problem dissapeared. Though our app still targets .net 4.0

like image 225
Pavel Voronin Avatar asked Aug 14 '12 15:08

Pavel Voronin


1 Answers

Finally I found the soultion.

Just added ScrollViewer.HorizontalScrollBarVisibility="Disabled"

For those who targets Framework v4.0
Recently we found a bug which our users had and the developers did not. The bug was again about DataGrid's width and alignment. Well, may be this was not really a bug but we had different behavior of the control. The research revealed that when installing .net framework 4.5 installer also updated .net framework 4.0. This update changed somehow DataGrid's behavior. (to the expected one) We asked our users to install framework 4.5 and the problem disappeared. Though our app still targets .net 4.0

like image 92
Pavel Voronin Avatar answered Nov 17 '22 18:11

Pavel Voronin