如何让最后一个DataGrid的列占据整个左侧空间? [英] How to make the last DataGrid's column occupy the whole left space?

查看:16
本文介绍了如何让最后一个DataGrid的列占据整个左侧空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先!我知道这看起来像是一种 dup 然而它不是.

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

我有一个网格作为 DataGrid.RowDetails 的数据模板.它有三列:两列带有 Width="Auto" 和带有 Width="*"

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>

如果 Grid 嵌套在单元格中,则此模板正好显示 3 列.但是当它用作 RowDetaislTemplate 时会出现第 4 个空列.这让我很生气.

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?

更新 1.它的样子:

更新 2.

我终于找到了灵魂.刚刚添加了 ScrollViewer.Horizo​​ntalScrollBarVisibility="Disabled"

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

现在可以了:

但我无法理解这种奇怪的行为.

But I cannot understand this odd behavior.

更新 3(可能对某人有帮助)

最近我们发现了一个我们的用户有而开发者没有的错误.该错误再次与 DataGrid 的宽度和对齐方式有关.好吧,可能这不是一个真正的错误,但我们有不同的控件行为.
研究表明,在安装 .net framework 4.5 时,安装程​​序也会更新 .net framework 4.0.此更新以某种方式改变了 DataGrid 的行为.(到预期的)
我们要求我们的用户安装框架 4.5,问题就消失了.虽然我们的应用仍然面向 .net 4.0

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

推荐答案

我终于找到了灵魂.

Finally I found the soultion.

刚刚添加了 ScrollViewer.Horizo​​ntalScrollBarVisibility="Disabled"

对于那些以 Framework v4.0 为目标的人
最近我们发现了一个我们的用户有而开发人员没有的错误.该错误再次与 DataGrid 的宽度和对齐方式有关.好吧,可能这不是一个真正的错误,但我们有不同的控件行为.研究表明,在安装 .net framework 4.5 时,安装程​​序也会更新 .net framework 4.0.此更新以某种方式改变了 DataGrid 的行为.(到预期的)我们要求我们的用户安装框架 4.5,问题就消失了.虽然我们的应用仍然面向 .net 4.0

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

这篇关于如何让最后一个DataGrid的列占据整个左侧空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆