From ca823a929481190c1cdae1b6cebd45a135791ca8 Mon Sep 17 00:00:00 2001 From: wang-yin1 <813860776@qq.com> Date: Tue, 15 Jul 2025 19:14:03 +0800 Subject: [PATCH] 2025-07-15 19:13 --- .../Extensions/ScrollViewerExtensions.cs | 68 ++++++++++++ VisionFrame/ViewModels/FlowTabViewModel.cs | 4 + VisionFrame/Views/FlowTabView.xaml | 101 +++++++++--------- 3 files changed, 125 insertions(+), 48 deletions(-) create mode 100644 VisionFrame/Extensions/ScrollViewerExtensions.cs diff --git a/VisionFrame/Extensions/ScrollViewerExtensions.cs b/VisionFrame/Extensions/ScrollViewerExtensions.cs new file mode 100644 index 0000000..b4858a5 --- /dev/null +++ b/VisionFrame/Extensions/ScrollViewerExtensions.cs @@ -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); } + } + } +} diff --git a/VisionFrame/ViewModels/FlowTabViewModel.cs b/VisionFrame/ViewModels/FlowTabViewModel.cs index b03f31c..55148d2 100644 --- a/VisionFrame/ViewModels/FlowTabViewModel.cs +++ b/VisionFrame/ViewModels/FlowTabViewModel.cs @@ -1100,6 +1100,10 @@ namespace VisionFrame.ViewModels { Application.Current.Dispatcher.Invoke(new Action(() => { + if (LogList.Count>1000) + { + LogList.RemoveAt(0); + } // 数据量增大 this.LogList.Add(new LogModel { diff --git a/VisionFrame/Views/FlowTabView.xaml b/VisionFrame/Views/FlowTabView.xaml index b228660..d4b98a6 100644 --- a/VisionFrame/Views/FlowTabView.xaml +++ b/VisionFrame/Views/FlowTabView.xaml @@ -4,6 +4,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:VisionFrame.Views" + xmlns:extensions="clr-namespace:VisionFrame.Extensions" xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:n="clr-namespace:VisionFrame.Nodes" xmlns:base="clr-namespace:VisionFrame.Base.TemplateSelector;assembly=VisionFrame.Base" @@ -457,11 +458,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + FontSize="16" VerticalAlignment="Center" Margin="0,0,3,0"/> @@ -471,7 +507,7 @@ + ItemsSource="{Binding ArgumentList}"> @@ -483,25 +519,25 @@ + VerticalContentAlignment="Center" + BorderThickness="0" + Background="Transparent" + Margin="2" FontWeight="Normal" + Foreground="#555"/> + Margin="1,3" BorderThickness="0" + ItemsSource="{Binding DataContext.ArgTypeList,RelativeSource={RelativeSource AncestorType=UserControl}}">