添加项目文件。
This commit is contained in:
34
TestingModule/Views/LogArea.xaml.cs
Normal file
34
TestingModule/Views/LogArea.xaml.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using TestingModule.ViewModels;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace TestingModule.Views
|
||||
{
|
||||
public partial class LogArea : UserControl
|
||||
{
|
||||
public LogArea()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
// 绑定 DataContext 后,订阅日志集合变化
|
||||
this.Loaded += (s, e) =>
|
||||
{
|
||||
if (DataContext is LogAreaViewModel vm)
|
||||
{
|
||||
vm.Logs.CollectionChanged += Logs_CollectionChanged;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void Logs_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
// 每次新增日志,滚动到最后一条
|
||||
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
|
||||
{
|
||||
if (this.LogListView.Items.Count > 0)
|
||||
{
|
||||
this.LogListView.ScrollIntoView(this.LogListView.Items[^1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user