使用新框架与技术代替旧框架与技术,实现涂装车间后道标签扫码程序
This commit is contained in:
46
RIZO_Application.Modules.LogModule/Views/SystemLog.xaml.cs
Normal file
46
RIZO_Application.Modules.LogModule/Views/SystemLog.xaml.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
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(); // 滚动条滚动到最底部
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user