using System.Collections.Specialized; using System.Windows.Controls; namespace SpdUp.Views; public partial class DebugLogView : UserControl { public DebugLogView() { InitializeComponent(); // Auto-scroll to bottom when new items are added if (LogList.ItemsSource is INotifyCollectionChanged ncc) { ncc.CollectionChanged += (_, _) => { if (DataContext is ViewModels.DebugLogViewModel vm && vm.AutoScroll && LogList.Items.Count > 0) { LogList.ScrollIntoView(LogList.Items[^1]); } }; } Loaded += (_, _) => { if (LogList.ItemsSource is INotifyCollectionChanged ncc2) { ncc2.CollectionChanged += (_, _) => { if (DataContext is ViewModels.DebugLogViewModel vm && vm.AutoScroll && LogList.Items.Count > 0) { LogList.ScrollIntoView(LogList.Items[^1]); } }; } }; } }