2025-07-15 19:13

This commit is contained in:
wang-yin1
2025-07-15 19:14:03 +08:00
parent ebc05c28b9
commit ca823a9294
3 changed files with 125 additions and 48 deletions

View File

@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace VisionFrame.Extensions
{
public class ScrollViewerExtensions
{
public static readonly DependencyProperty AlwaysScrollToEndProperty = DependencyProperty.RegisterAttached("AlwaysScrollToEnd", typeof(bool), typeof(ScrollViewerExtensions), new PropertyMetadata(false, AlwaysScrollToEndChanged));
private static bool _autoScroll;
private static void AlwaysScrollToEndChanged(object sender, DependencyPropertyChangedEventArgs e)
{
ScrollViewer scroll = sender as ScrollViewer;
if (scroll != null)
{
bool alwaysScrollToEnd = (e.NewValue != null) && (bool)e.NewValue;
if (alwaysScrollToEnd)
{
scroll.ScrollToEnd();
scroll.ScrollChanged += ScrollChanged;
// scroll.SizeChanged += Scroll_SizeChanged;
}
else { scroll.ScrollChanged -= ScrollChanged; /*scroll.ScrollChanged -= ScrollChanged; */}
}
else { throw new InvalidOperationException("The attached AlwaysScrollToEnd property can only be applied to ScrollViewer instances."); }
}
//private static void Scroll_SizeChanged(object sender, SizeChangedEventArgs e)
//{
// ScrollViewer scroll = sender as ScrollViewer;
// if (scroll == null) { throw new InvalidOperationException("The attached AlwaysScrollToEnd property can only be applied to ScrollViewer instances."); }
// double d = scroll.ActualHeight + scroll.ViewportHeight + scroll.ExtentHeight;
// scroll.ScrollToVerticalOffset(d);
//}
public static bool GetAlwaysScrollToEnd(ScrollViewer scroll)
{
if (scroll == null) { throw new ArgumentNullException("scroll"); }
return (bool)scroll.GetValue(AlwaysScrollToEndProperty);
}
public static void SetAlwaysScrollToEnd(ScrollViewer scroll, bool alwaysScrollToEnd)
{
if (scroll == null) { throw new ArgumentNullException("scroll"); }
scroll.SetValue(AlwaysScrollToEndProperty, alwaysScrollToEnd);
}
private static void ScrollChanged(object sender, ScrollChangedEventArgs e)
{
ScrollViewer scroll = sender as ScrollViewer;
if (scroll == null) { throw new InvalidOperationException("The attached AlwaysScrollToEnd property can only be applied to ScrollViewer instances."); }
if (e.ExtentHeightChange == 0) { _autoScroll = scroll.VerticalOffset == scroll.ScrollableHeight; }
if (_autoScroll && e.ExtentHeightChange != 0) { scroll.ScrollToVerticalOffset(scroll.ExtentHeight); }
}
}
}

View File

@@ -1100,6 +1100,10 @@ namespace VisionFrame.ViewModels
{ {
Application.Current.Dispatcher.Invoke(new Action(() => Application.Current.Dispatcher.Invoke(new Action(() =>
{ {
if (LogList.Count>1000)
{
LogList.RemoveAt(0);
}
// 数据量增大 // 数据量增大
this.LogList.Add(new LogModel this.LogList.Add(new LogModel
{ {

View File

@@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:VisionFrame.Views" xmlns:local="clr-namespace:VisionFrame.Views"
xmlns:extensions="clr-namespace:VisionFrame.Extensions"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:n="clr-namespace:VisionFrame.Nodes" xmlns:n="clr-namespace:VisionFrame.Nodes"
xmlns:base="clr-namespace:VisionFrame.Base.TemplateSelector;assembly=VisionFrame.Base" xmlns:base="clr-namespace:VisionFrame.Base.TemplateSelector;assembly=VisionFrame.Base"
@@ -457,11 +458,46 @@
<TabControl Grid.Row="1" Margin="0,5,0,0" <TabControl Grid.Row="1" Margin="0,5,0,0"
BorderThickness="0,1,0,0" BorderBrush="#1f71e5" BorderThickness="0,1,0,0" BorderBrush="#1f71e5"
Background="#5FFF" Padding="0"> Background="#5FFF" Padding="0">
<TabItem Style="{StaticResource NormalTabStyle}">
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="&#xe7c3;" FontFamily="{StaticResource Iconfont}"
FontSize="16" VerticalAlignment="Center" Margin="0,0,3,0"/>
<TextBlock Text="运行日志" VerticalAlignment="Center"/>
</StackPanel>
</TabItem.Header>
<ScrollViewer extensions:ScrollViewerExtensions.AlwaysScrollToEnd="True" VerticalScrollBarVisibility="Hidden">
<ItemsControl ItemsSource="{Binding LogList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Height="28" Margin="3,1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="80"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Time ,StringFormat=HH:mm:ss}"
VerticalAlignment="Center" HorizontalAlignment="Center"
Foreground="#888"/>
<TextBlock Text="{Binding NodeName}" Foreground="#333"
Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBlock Text="{Binding LogMessage}" Grid.Column="2" Foreground="#333"
VerticalAlignment="Center"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</TabItem>
<TabItem Style="{StaticResource NormalTabStyle}"> <TabItem Style="{StaticResource NormalTabStyle}">
<TabItem.Header> <TabItem.Header>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<TextBlock Text="&#xe655;" FontFamily="{StaticResource Iconfont}" <TextBlock Text="&#xe655;" FontFamily="{StaticResource Iconfont}"
FontSize="16" VerticalAlignment="Center" Margin="0,0,3,0"/> FontSize="16" VerticalAlignment="Center" Margin="0,0,3,0"/>
<TextBlock Text="流程参数管理" VerticalAlignment="Center"/> <TextBlock Text="流程参数管理" VerticalAlignment="Center"/>
</StackPanel> </StackPanel>
</TabItem.Header> </TabItem.Header>
@@ -471,7 +507,7 @@
<RowDefinition Height="auto"/> <RowDefinition Height="auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<ListBox Background="Transparent" BorderThickness="0" <ListBox Background="Transparent" BorderThickness="0"
ItemsSource="{Binding ArgumentList}"> ItemsSource="{Binding ArgumentList}">
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<Grid Height="30"> <Grid Height="30">
@@ -483,25 +519,25 @@
<Border Margin="3,3,1,3" CornerRadius="3" Background="#FFF"> <Border Margin="3,3,1,3" CornerRadius="3" Background="#FFF">
<TextBox Text="{Binding ArgName,UpdateSourceTrigger=PropertyChanged}" <TextBox Text="{Binding ArgName,UpdateSourceTrigger=PropertyChanged}"
VerticalContentAlignment="Center" VerticalContentAlignment="Center"
BorderThickness="0" BorderThickness="0"
Background="Transparent" Background="Transparent"
Margin="2" FontWeight="Normal" Margin="2" FontWeight="Normal"
Foreground="#555"/> Foreground="#555"/>
</Border> </Border>
<ComboBox Grid.Column="1" SelectedItem="{Binding ArgType}" <ComboBox Grid.Column="1" SelectedItem="{Binding ArgType}"
Margin="1,3" BorderThickness="0" Margin="1,3" BorderThickness="0"
ItemsSource="{Binding DataContext.ArgTypeList,RelativeSource={RelativeSource AncestorType=UserControl}}"> ItemsSource="{Binding DataContext.ArgTypeList,RelativeSource={RelativeSource AncestorType=UserControl}}">
</ComboBox> </ComboBox>
<Button Content="&#xe660;" FontFamily="{StaticResource Iconfont}" <Button Content="&#xe660;" FontFamily="{StaticResource Iconfont}"
Grid.Column="2" Style="{StaticResource DeleteElementButtonStyle}" Grid.Column="2" Style="{StaticResource DeleteElementButtonStyle}"
FontSize="10" Width="22" Height="22" FontSize="10" Width="22" Height="22"
Margin="0" Background="Transparent" Margin="0" Background="Transparent"
Command="{Binding DataContext.DelArgumentCommand,RelativeSource={RelativeSource AncestorType=UserControl}}" Command="{Binding DataContext.DelArgumentCommand,RelativeSource={RelativeSource AncestorType=UserControl}}"
CommandParameter="{Binding}"/> CommandParameter="{Binding}"/>
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
@@ -522,44 +558,13 @@
</ListBox> </ListBox>
<Border Height="1" Background="#DDD" VerticalAlignment="Top" <Border Height="1" Background="#DDD" VerticalAlignment="Top"
Grid.Row="1" Margin="5,0"/> Grid.Row="1" Margin="5,0"/>
<Button Grid.Row="1" Height="30" Content="添加参数" Width="120" <Button Grid.Row="1" Height="30" Content="添加参数" Width="120"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Margin="5" Command="{Binding AddArgumentCommand}"/> Margin="5" Command="{Binding AddArgumentCommand}"/>
</Grid> </Grid>
</TabItem> </TabItem>
<TabItem Style="{StaticResource NormalTabStyle}">
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="&#xe7c3;" FontFamily="{StaticResource Iconfont}"
FontSize="16" VerticalAlignment="Center" Margin="0,0,3,0"/>
<TextBlock Text="运行日志" VerticalAlignment="Center"/>
</StackPanel>
</TabItem.Header>
<ItemsControl ItemsSource="{Binding LogList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Height="28" Margin="3,1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="80"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Time ,StringFormat=HH:mm:ss}"
VerticalAlignment="Center" HorizontalAlignment="Center"
Foreground="#888"/>
<TextBlock Text="{Binding NodeName}" Foreground="#333"
Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBlock Text="{Binding LogMessage}" Grid.Column="2" Foreground="#333"
VerticalAlignment="Center"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</TabItem>
</TabControl> </TabControl>
</Grid> </Grid>
</Grid> </Grid>