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

The vertical scrollbar of DataGrid cannot be automatically generated #1062

Open
telesa864 opened this issue Apr 19, 2024 · 2 comments
Open
Labels
bug Something isn't working

Comments

@telesa864
Copy link

telesa864 commented Apr 19, 2024

Describe the bug

If I do not set the Height of the DataGrid control, but set it to a certain Grid.Row, the vertical scrollbar cannot be automatically generated, which is normal in version 2.1.0.
image
image

To Reproduce

.

Expected behavior

When I have multiple rows in a Grid, and one of them is a DataGrid with RowDefinition Height set to "*", the vertical scrollbar for the DataGrid is generated correctly, instead of the entire Grid's vertical scrollbar.

Screenshots

No response

OS version

windows11

.NET version

8.0

WPF-UI NuGet version

3.0.4

Additional context

No response

@telesa864 telesa864 added the bug Something isn't working label Apr 19, 2024
@programxo
Copy link

programxo commented May 16, 2024

To ensure the vertical scrollbar of the DataGrid is correctly generated when placed in a Grid with RowDefinition set to "*", you can handle the SizeChanged event of the Page to dynamically adjust the height of the DataGrid.

Here's an example:

XAML:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>

    <ui:DataGrid x:Name="MainGrid"
                 ItemsSource="{Binding YourItemsSource}"
                 AutoGenerateColumns="True"
                 CanUserAddRows="True"
                 Grid.Row="0">

    </ui:DataGrid>

    <TextBlock Grid.Row="1" Text="Status Bar" HorizontalAlignment="Center" />
</Grid>

Code-Behind (C#):

using System.Windows;

namespace YourNamespace
{
public partial class YourPage : Page
{
public YourPage()
{
InitializeComponent();
}

    private void Page_SizeChanged(object sender, SizeChangedEventArgs e)
    {
         double totalHeight = this.ActualHeight;
        double statusBarHeight = 40; // Adjust based on actual status bar height
        double remainingHeight = totalHeight - statusBarHeight;

        MainGrid.Height = remainingHeight;
    }
}

}

By handling the SizeChanged event, you can ensure that the DataGrid height is dynamically adjusted, and the vertical scrollbar is generated correctly.

@telesa864
Copy link
Author

@programxo I'm sure you're right, but 2.1.0 has the ability to automatically generate a vertical scroll bar without dynamically setting the height of the DataGrid.Is this a destructive change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants