PlaygroundPageView.axaml.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Linq;
  3. using System.Threading;
  4. using Avalonia;
  5. using Avalonia.Controls;
  6. using Avalonia.Markup.Xaml;
  7. using Avalonia.Threading;
  8. namespace VirtualizationDemo.Views;
  9. public partial class PlaygroundPageView : UserControl
  10. {
  11. private DispatcherTimer _timer;
  12. public PlaygroundPageView()
  13. {
  14. InitializeComponent();
  15. _timer = new DispatcherTimer
  16. {
  17. Interval = TimeSpan.FromMilliseconds(500),
  18. };
  19. _timer.Tick += TimerTick;
  20. }
  21. protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
  22. {
  23. base.OnAttachedToVisualTree(e);
  24. _timer.Start();
  25. }
  26. protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
  27. {
  28. base.OnDetachedFromVisualTree(e);
  29. _timer.Stop();
  30. }
  31. private void TimerTick(object? sender, EventArgs e)
  32. {
  33. var message = $"Realized {list.GetRealizedContainers().Count()} of {list.ItemsPanelRoot?.Children.Count}";
  34. itemCount.Text = message;
  35. }
  36. }