使用新框架与技术代替旧框架与技术,实现涂装车间后道标签扫码程序
This commit is contained in:
24
RIZO_Application.Modules.LogModule/Views/SystemLog.xaml
Normal file
24
RIZO_Application.Modules.LogModule/Views/SystemLog.xaml
Normal file
@@ -0,0 +1,24 @@
|
||||
<UserControl x:Class="RIZO_Application.Modules.LogModule.Views.SystemLog"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:RIZO_Application.Modules.LogModule"
|
||||
xmlns:prism="http://prismlibrary.com/"
|
||||
prism:ViewModelLocator.AutoWireViewModel="True">
|
||||
<Grid>
|
||||
<GroupBox Header="系统日志" HorizontalAlignment="Stretch">
|
||||
<Grid>
|
||||
<TextBox
|
||||
x:Name="LogTextBox"
|
||||
Text="{Binding LogMessage}"
|
||||
TextWrapping="Wrap"
|
||||
AcceptsReturn="True"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalScrollBarVisibility="Auto"
|
||||
IsReadOnly="True"
|
||||
/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
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