Skip to content

没有数据时DataGrid的表头无法显示 #903

@dswfort

Description

@dswfort

Describe the bug
自从3.0升级到3.2后发现用到DataGrid的地方,当ItemSource.Count=0时,DataGrid不会显示ColumnHeader,翻看了其模板后发现是特意这么改的。判断逻辑为当HasItem=False,即没有数据的时候显示的是hc:Empty,如下。

<hc:ToggleBlock IsChecked="{Binding HasItems,RelativeSource={RelativeSource TemplatedParent},Mode=OneWay}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch">
    <hc:ToggleBlock.CheckedContent>
        <ScrollViewer x:Name="DG_ScrollViewer" Focusable="false">
            ...
        </ScrollViewer>
    </hc:ToggleBlock.CheckedContent>
    <hc:ToggleBlock.UnCheckedContent>
        <hc:Empty />
    </hc:ToggleBlock.UnCheckedContent>
</hc:ToggleBlock>

这样一来表格区域一片空白,看着会很奇怪,就比如我这个界面:

显示效果

尤其是在一些设置界面,首次打开肯定是没有数据的,也不显示表头。。。

Expected behavior
是不是可以考虑参照Web上的表格显示效果,保留表头,下方显示hc:Empty,并给hc:Empty定以一个默认模板,这样不会导致界面上啥都不显示。

Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • .net: 4.6.1
  • IDE vs2019
  • Version 3.2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions