using System.Collections.Specialized; using System.Windows.Controls; using HC_APTBS.ViewModels.Pages; namespace HC_APTBS.Views.Pages { /// /// Code-behind for the Developer Tools page. Auto-scrolls the log to the /// bottom when entries are appended so the latest TX/RX is always visible. /// Compiled into Debug builds only — see HC_APTBS.csproj. /// public partial class DeveloperPage : UserControl { private DeveloperPageViewModel? _vm; public DeveloperPage() { InitializeComponent(); DataContextChanged += OnDataContextChanged; } private void OnDataContextChanged(object sender, System.Windows.DependencyPropertyChangedEventArgs e) { if (_vm is { } old) ((INotifyCollectionChanged)old.Log).CollectionChanged -= OnLogChanged; _vm = DataContext as DeveloperPageViewModel; if (_vm is not null) ((INotifyCollectionChanged)_vm.Log).CollectionChanged += OnLogChanged; } private void OnLogChanged(object? sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Add) Dispatcher.BeginInvoke(() => LogScroller.ScrollToBottom()); } } }