Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dswfort opened this issue Jul 8, 2021 · 2 comments
Closed

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

dswfort opened this issue Jul 8, 2021 · 2 comments

Comments

@dswfort
Copy link

dswfort commented Jul 8, 2021

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
@ghost1372
Copy link
Member

ghost1372 commented Jul 8, 2021

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

@NaBian NaBian closed this as completed in 77f273f Jul 8, 2021
@lwqwag
Copy link
Contributor

lwqwag commented Jul 30, 2021

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 ();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants