From 6364f5f4d1b0fba26aa4b2d32679bed4b22b4563 Mon Sep 17 00:00:00 2001 From: XuShanQiXun <3401460572@qq.com> Date: Sun, 8 Jun 2025 09:12:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=8F=9C=E5=8D=95=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=E5=92=8C=E5=BC=82=E6=AD=A5=E5=8A=A0=E8=BD=BD=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 `MaterialTrayMenuItem.xaml` 中添加命名空间,更新菜单项样式,增加悬停和点击动画效果,提升用户交互体验。新增上下文菜单样式,包含透明度和缩放动画。 在 `LoginWindow.xaml.cs` 中将 `Window_Loaded` 方法改为异步,增强窗口加载时的连接稳定性,并添加连接服务器的逻辑及错误处理。 在 `MainWindow.xaml` 中移除 `TextBox` 控件的 `Foreground` 属性设置,简化样式,保持界面整洁。 --- chatclient/Data/MaterialTrayMenuItem.xaml | 135 ++++++++++++++++++++-- chatclient/LoginWindow.xaml.cs | 24 +++- chatclient/MainWindow.xaml | 2 +- 3 files changed, 145 insertions(+), 16 deletions(-) diff --git a/chatclient/Data/MaterialTrayMenuItem.xaml b/chatclient/Data/MaterialTrayMenuItem.xaml index 5387ae3..d7abe29 100644 --- a/chatclient/Data/MaterialTrayMenuItem.xaml +++ b/chatclient/Data/MaterialTrayMenuItem.xaml @@ -1,7 +1,12 @@ - + + + + + \ No newline at end of file diff --git a/chatclient/LoginWindow.xaml.cs b/chatclient/LoginWindow.xaml.cs index f28d3c6..b27f93a 100644 --- a/chatclient/LoginWindow.xaml.cs +++ b/chatclient/LoginWindow.xaml.cs @@ -277,10 +277,28 @@ namespace chatclient } }); } - public void Window_Loaded(object sender, RoutedEventArgs e) + public async void Window_Loaded(object sender, RoutedEventArgs e) { log.Info("登录窗口已加载"); - + if (MainWindow.Client?.Connected == false) + { + log.Info("未连接服务器,尝试连接"); + // 异步连接操作 + await Task.Run(() => + { + try + { + MainWindow.Client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + MainWindow.Client?.Connect(IPAddress.Parse(Server.ServerIP), Server.ServerPort); + MainWindow.StartReceive(); + } + catch (Exception ex) + { + log.Error($"连接失败: {ex.Message}"); + MainWindow.Client?.Close(); + } + }); + } try { string tempPath = System.IO.Path.GetTempPath(); @@ -323,7 +341,7 @@ namespace chatclient log.Error("保存登录信息到临时文件失败", ex); } } - if (MainWindow.token == null) Application.Current.Shutdown(); + if (MainWindow.token == null) Application.Current.Shutdown(); } } } diff --git a/chatclient/MainWindow.xaml b/chatclient/MainWindow.xaml index 1c1c515..cf720da 100644 --- a/chatclient/MainWindow.xaml +++ b/chatclient/MainWindow.xaml @@ -125,7 +125,7 @@ + TextWrapping="Wrap" MinHeight="50" MaxHeight="100" Margin="5" BorderBrush="#00000000"/>