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

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

问题描述

首先!
我知道它似乎是一种 dup 仍然不是。

我有一个网格作为 DataGrid.RowDetails 。
它具有三列:两列带有 Width = Auto 和3d带有 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 时,会出现第四个空列。
这使我发疯。

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 (可能对某人有所帮助)

Update 3 (may be helpful to someone)

最近,我们发现了一个用户所拥有的错误,而开发人员却没有。该错误再次与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天全站免登陆