lepoco / wpfui

WPF UI provides the Fluent experience in your known and loved WPF framework. Intuitive design, themes, navigation and new immersive controls. All natively and effortlessly.
https://wpfui.lepo.co
MIT License
7.04k stars 667 forks source link

The vertical scrollbar of DataGrid cannot be automatically generated #1062

Closed telesa864 closed 2 weeks ago

telesa864 commented 2 months ago

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

programxo commented 1 month ago

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:

<Page x:Class="YourNamespace.YourPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="DataPage" SizeChanged="Page_SizeChanged">

<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 commented 1 month ago

@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?