2021-08-01 18:02:46 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Specialized;
|
2021-02-23 18:03:37 +08:00
|
|
|
using System.Windows;
|
|
|
|
using System.Windows.Controls;
|
2021-08-01 18:02:46 +08:00
|
|
|
using System.Windows.Media;
|
2021-02-23 18:03:37 +08:00
|
|
|
|
|
|
|
#nullable enable
|
|
|
|
namespace BililiveRecorder.WPF.Controls
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Interaction logic for LogPanel.xaml
|
|
|
|
/// </summary>
|
|
|
|
public partial class LogPanel : UserControl
|
|
|
|
{
|
|
|
|
public LogPanel()
|
|
|
|
{
|
|
|
|
this.InitializeComponent();
|
2021-08-01 18:02:46 +08:00
|
|
|
((INotifyCollectionChanged)this.logView.Items).CollectionChanged += this.LogView_CollectionChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void LogView_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (!this.logView.IsMouseOver && VisualTreeHelper.GetChildrenCount(this.logView) > 0)
|
|
|
|
{
|
|
|
|
var border = (Border)VisualTreeHelper.GetChild(this.logView, 0);
|
|
|
|
var scrollViewer = (ScrollViewer)VisualTreeHelper.GetChild(border, 0);
|
|
|
|
scrollViewer.ScrollToBottom();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception)
|
|
|
|
{ }
|
2021-02-23 18:03:37 +08:00
|
|
|
}
|
|
|
|
|
2022-06-28 16:10:41 +08:00
|
|
|
private static readonly TimeSpan OneSecond = TimeSpan.FromSeconds(1);
|
|
|
|
private DateTimeOffset lastSizeChanged = DateTimeOffset.MinValue;
|
|
|
|
|
2021-02-23 18:03:37 +08:00
|
|
|
private void ListView_SizeChanged(object sender, SizeChangedEventArgs e)
|
|
|
|
{
|
2022-06-07 22:41:09 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if (sender is not ListView listView) return;
|
|
|
|
if (listView.View is not GridView view) return;
|
2021-02-23 18:03:37 +08:00
|
|
|
|
2022-06-28 16:10:41 +08:00
|
|
|
var now = DateTimeOffset.Now;
|
|
|
|
|
|
|
|
if (now - this.lastSizeChanged < OneSecond)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.lastSizeChanged = now;
|
|
|
|
|
2022-06-07 22:41:09 +08:00
|
|
|
var w = listView.ActualWidth - SystemParameters.VerticalScrollBarWidth - 105 - 60 - 105;
|
2021-02-23 18:03:37 +08:00
|
|
|
|
2022-06-07 22:41:09 +08:00
|
|
|
view.Columns[0].Width = 105;
|
|
|
|
view.Columns[1].Width = 60;
|
|
|
|
view.Columns[2].Width = 105;
|
|
|
|
view.Columns[3].Width = w;
|
|
|
|
}
|
|
|
|
catch (Exception) { }
|
2021-02-23 18:03:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|