Skip to content

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

Closed

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

Activity

  1. ghost1372 commented on Jul 8, 2021

    @ghost1372
    Member

    First, please type in English

    Second, if you want to display hc:Empty, you need to set up an AttachedProperty hc:Empty.ShowEmpty="true" for the datagrid.

    also if you need to use hc:Empty in another way again you should set hc:Empty.ShowEmpty="true"

    please read docs

  2. lwqwag commented on Jul 30, 2021

    @lwqwag
    Contributor

    I found a issue when set DataGridTextColumn Width="*“ the header not visible when data is empty as blow code.

    <DataGrid hc:Empty.ShowEmpty="True" AutoGenerateColumns="False" CanUserAddRows="False" CanUserSortColumns="False" HeadersVisibility="All" ItemsSource="{Binding TestData}"> <DataGrid.Columns> <DataGridTextColumn Width="*" Header="TEST1" /> <DataGridTextColumn Width="*" Header="TEST2" /> <DataGridTextColumn Width="*" Header="TEST3" /> <DataGridTextColumn Width="*" Header="TEST4" /> </DataGrid.Columns> </DataGrid>
    ObservableCollection<Class> TestData=new ();

  3. added a commit that references this issue on Mar 28, 2024
    77f273f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      ⌂ 换网址