Closed telesa864 closed 2 weeks 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.
@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?
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.
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