From 8afe78a16f25a54edcd1a4099d3e991bbd58e086 Mon Sep 17 00:00:00 2001 From: zhangxy Date: Thu, 28 Aug 2025 08:46:55 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=96=B0=E5=A2=9E=E6=97=B6=E9=92=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SocketExample/TCPWindowV2.xaml | 14 +++++++++++--- SocketExample/TCPWindowV2.xaml.cs | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/SocketExample/TCPWindowV2.xaml b/SocketExample/TCPWindowV2.xaml index dbf8937..bbbe004 100644 --- a/SocketExample/TCPWindowV2.xaml +++ b/SocketExample/TCPWindowV2.xaml @@ -116,14 +116,22 @@ + - - - diff --git a/SocketExample/TCPWindowV2.xaml.cs b/SocketExample/TCPWindowV2.xaml.cs index 0b21c02..619e3cd 100644 --- a/SocketExample/TCPWindowV2.xaml.cs +++ b/SocketExample/TCPWindowV2.xaml.cs @@ -19,6 +19,7 @@ using System.Windows.Markup; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; +using System.Windows.Threading; using System.Xml; using Google.Protobuf.WellKnownTypes; using K4os.Compression.LZ4.Streams.Abstractions; @@ -65,10 +66,13 @@ namespace SocketExample public static double? WindowHeight { get; set; } public static WindowState? OriginWindowState { get; set; } public static int? Buttonflag { get; set; } + private DispatcherTimer _timer; + public TCPWindowV2() { InitializeComponent(); EnsureFolderExists("日志文件夹"); + InitializeTimer(); this.Closing += TCPWindowV2_Closing; PanelContainer.ItemsSource = items; SaveWindowSettings(); @@ -521,6 +525,27 @@ namespace SocketExample OriginWindowState = this.WindowState; } + private void InitializeTimer() + { + _timer = new DispatcherTimer(); + _timer.Interval = TimeSpan.FromSeconds(1); // 每秒更新一次 + _timer.Tick += Timer_Tick; + _timer.Start(); + + // 立即显示时间 + UpdateClock(); + } + + private void Timer_Tick(object sender, EventArgs e) + { + UpdateClock(); + } + + private void UpdateClock() + { + DateTime now = DateTime.Now; + ClockText.Text = now.ToString("HH:mm:ss"); + } #endregion public class MyService : TcpService