47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
|
|
using System.Windows;
|
|||
|
|
using System.Windows.Controls;
|
|||
|
|
using RIZO_Application.Infrastructure.CustomAttribute;
|
|||
|
|
using RIZO_Application.Modules.LogModule.ViewModels;
|
|||
|
|
|
|||
|
|
namespace RIZO_Application.Modules.LogModule.Views
|
|||
|
|
{
|
|||
|
|
[AutoRegisterView(ViewName = "SystemLog")]
|
|||
|
|
/// <summary>
|
|||
|
|
/// SystemLog.xaml 的交互逻辑
|
|||
|
|
/// </summary>
|
|||
|
|
public partial class SystemLog : UserControl
|
|||
|
|
{
|
|||
|
|
public SystemLog()
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
InitializeComponent();
|
|||
|
|
Loaded += SystemLogView_Loaded;
|
|||
|
|
}
|
|||
|
|
private void SystemLogView_Loaded(object sender, RoutedEventArgs e)
|
|||
|
|
{
|
|||
|
|
var viewModel = (SystemLogViewModel)DataContext;
|
|||
|
|
if (viewModel != null)
|
|||
|
|
{
|
|||
|
|
viewModel.LogUpdated += ViewModel_LogUpdated;
|
|||
|
|
// 初始加载时滚动到底部
|
|||
|
|
ScrollToBottom();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void ViewModel_LogUpdated(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
// 日志更新时滚动到底部(使用 Dispatcher 确保 UI 已更新)
|
|||
|
|
Dispatcher.Invoke(ScrollToBottom);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void ScrollToBottom()
|
|||
|
|
{
|
|||
|
|
if (LogTextBox != null && LogTextBox.Text != null)
|
|||
|
|
{
|
|||
|
|
LogTextBox.CaretIndex = LogTextBox.Text.Length; // 将光标移到末尾
|
|||
|
|
LogTextBox.ScrollToEnd(); // 滚动条滚动到最底部
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|