Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...