Files

45 lines
1.2 KiB
C#
Raw Permalink Normal View History

2026-04-04 13:30:13 +02:00
using System.Collections.Specialized;
using Avalonia.Controls;
using Avalonia.LogicalTree;
2026-04-05 10:13:12 +02:00
using Serilog.Sinks.LogView.Core.Logging;
2026-04-04 13:30:13 +02:00
namespace LogViewer.Avalonia;
public partial class LogViewerControl : UserControl
{
public LogViewerControl()
2026-04-04 15:36:30 +02:00
{
InitializeComponent();
}
2026-04-04 13:30:13 +02:00
2026-04-05 08:00:09 +02:00
private ILogDataStoreCore? vm;
2026-04-04 13:30:13 +02:00
private LogModel? item;
private void OnDataContextChanged(object? sender, EventArgs e)
{
if (DataContext is null)
return;
2026-04-05 08:00:09 +02:00
vm = (ILogDataStoreCore)DataContext;
2026-04-04 13:30:13 +02:00
vm.DataStore.Entries.CollectionChanged += OnCollectionChanged;
}
private void OnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
2026-04-04 15:36:30 +02:00
=> item = MyDataGrid.ItemsSource.Cast<LogModel>().LastOrDefault();
2026-04-04 13:30:13 +02:00
private void OnLayoutUpdated(object? sender, EventArgs e)
{
if (CanAutoScroll.IsChecked != true || item is null)
return;
MyDataGrid.ScrollIntoView(item, null);
item = null;
}
private void OnDetachedFromLogicalTree(object? sender, LogicalTreeAttachmentEventArgs e)
{
if (vm is null) return;
vm.DataStore.Entries.CollectionChanged -= OnCollectionChanged;
}
}