From e2b4caa94fc3a69a75d4657d9bf08593cc8da02d Mon Sep 17 00:00:00 2001 From: Kevin B Date: Wed, 7 Aug 2024 12:11:17 -0700 Subject: [PATCH] Adding sample of data virtualization (#3645) --- src/MainDemo.Wpf/Domain/TreesViewModel.cs | 15 ++++++++++++++- src/MainDemo.Wpf/Trees.xaml | 13 +++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/MainDemo.Wpf/Domain/TreesViewModel.cs b/src/MainDemo.Wpf/Domain/TreesViewModel.cs index de5c92de73..4cd810e569 100644 --- a/src/MainDemo.Wpf/Domain/TreesViewModel.cs +++ b/src/MainDemo.Wpf/Domain/TreesViewModel.cs @@ -1,6 +1,7 @@ using System.Collections; using System.Collections.ObjectModel; using System.Windows.Documents; +using CommunityToolkit.Mvvm.ComponentModel; using MaterialDesignDemo.Shared.Domain; using MaterialDesignThemes.Wpf; @@ -48,12 +49,24 @@ public class Planet public double Velocity { get; set; } } -public class TestItem +public partial class TestItem : ObservableObject { public TestItem? Parent { get; set; } public string Name { get; } public ObservableCollection Items { get; } + // This property is used to determine if the item is expanded or not. + // With the TreeListView control, the UI items are virtualized. Without + // this property, the IsExpanded state of the TreeListViewItem would be lost + // when it is recycled. + // + // For more information see: + // https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/issues/3640#issuecomment-2274086113 + // + // https://learn.microsoft.com/dotnet/desktop/wpf/advanced/optimizing-performance-controls?view=netframeworkdesktop-4.8&WT.mc_id=DT-MVP-5003472 + [ObservableProperty] + private bool _isExpanded; + public TestItem(string name, IEnumerable items) { Name = name; diff --git a/src/MainDemo.Wpf/Trees.xaml b/src/MainDemo.Wpf/Trees.xaml index 0de4d4c8f2..994415ba0b 100644 --- a/src/MainDemo.Wpf/Trees.xaml +++ b/src/MainDemo.Wpf/Trees.xaml @@ -231,6 +231,19 @@ + + + +