horizontal scrollbar not showing on datagrid when data is empty and headers do not fit on screen

前端 未结 2 1243
野性不改
野性不改 2021-01-29 16:40

I have tried the following :

ScrollViewer.CanContentScroll=\"True\"
ScrollViewer.HorizontalScrollBarVisibility=\"Visible\"

But it does not seem

相关标签:
2条回答
  • 2021-01-29 17:15

    the below solution will work. since listbox width is set to datagrid width scroll bar will be visble.

    <ScrollViewer HorizontalScrollBarVisibility="Auto" CanContentScroll="True">
                <Grid>
                    <ListBox Width="{Binding ElementName=myGrid,Path=ActualWidth}"></ListBox>
                    <DataGrid Name="myGrid"></DataGrid>
                </Grid>
    
            </ScrollViewer>
    
    0 讨论(0)
  • 2021-01-29 17:23

    There must be a possibility to do it, because Extended WPF Toolkit has done it!


    Lets assume that you have e.g. this class:

    public class ExampleClass
    {
        public int LongPropertyNameA;
        public int LongPropertyNameB;
        public int LongPropertyNameC;
        public int LongPropertyNameD;
        public int LongPropertyNameE;
        public int LongPropertyNameF;
    }
    

    The normal approach looks like this:
    The Headers are hidden. The XAML Code looks e.g. like this:

    <busGeneratorMvvm:CustomDataGrid ItemsSource="{Binding YourData}" IsReadOnly="True" />
    

    When you use the WPT Toolkit DataGrid Library (called Xceed.Wpf.DataGrid.dll) the grid looks like this with the scrollbars you want:
    The XAML Code looks e.g. like this:

    <xcdg:DataGridControl ItemsSource="{Binding YourData}" >
    

    where xcdg is the namespace defined in the Window tag with this XAML Code:

    <Window ...
            xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
            ...
        >
    

    Conclusion:
    If you want it very easy download the Xceed WPF Toolkit and use the DataGridControl.

    • Download the .dll from the website (search the internet for the free version)
    • Add the .dll to the references of your project
    • Use and enjoy the DataGridControl

    Hope it helps!

    0 讨论(0)
提交回复
热议问题