ListView does not scroll correctly
Describe the bug
When using a ListView the Listview will not scroll as expected when many items are in the list, instead the whole page will scroll.
To Reproduce
- Create a new "Compact" WPF UI project from project templates.
- Change XAML of Dashboard page to:
<DockPanel>
<TextBlock DockPanel.Dock="Top" Text="Sample Text" FontSize="20" FontWeight="Bold" FontStyle="Italic" Margin="0, 0, 0, 15"/>
<ListView ItemsSource="{Binding ViewModel.ListViewItems}" />
</DockPanel>
- Change the corresponding ViewModel to:
using System.Collections.ObjectModel;
using Bogus;
namespace ListViewTest.ViewModels.Pages;
public partial class DashboardViewModel : ObservableObject
{
[ObservableProperty]
private ObservableCollection<Person> _listViewItems;
public DashboardViewModel()
{
var listViewItems = new Faker<Person>()
.RuleFor(u => u.FirstName, f => f.Name.FirstName())
.RuleFor(u => u.LastName, f => f.Name.LastName())
.Generate(150);
ListViewItems = new ObservableCollection<Person>(listViewItems);
}
}
public record Person
{
public string FirstName { get; init; }
public string LastName { get; init; }
public override string ToString()
{
return $"{FirstName} {LastName}";
}
}
Expected behavior
Only the content part of the ListView should scroll.
Screenshots
No response
OS version
Windows 10 & 11
.NET version
.NET 8
WPF-UI NuGet version
Latest from Main
Additional context
No response
Hello @afluegge,
To disable whole page scrolling, you need to add the following line to the opening tag of the page (see screenshot below): ScrollViewer.CanContentScroll="False"
By default, the content of the whole page is scrollable.
Let me know if that doesn't work.
I dunno, I just feel like all Pages should just be unscrollable (don't add a ScrollView in the Control hierarchy).
This way the UI is smoother and the user can still add a ScrollViewer / StackView (or their equivalent visualizing version) if needed.