From 015535c100b23f0b880342afe051331feb299193 Mon Sep 17 00:00:00 2001 From: XuShanQiXun <3401460572@qq.com> Date: Sun, 22 Jun 2025 00:55:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=B6=E9=97=B4=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E8=BD=AC=E6=8D=A2=E5=99=A8=E5=92=8C=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E7=A9=BA=E9=97=B4=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 `App.xaml` 中添加了对 `chatclient.Data` 命名空间的引用。 在 `ChatDataModel.cs` 中移除不必要的 `using` 语句,添加对 `System.Windows` 和 `System.Windows.Media.Imaging` 的引用,并为 `ConvertBack` 方法添加文档注释。 在 `MainWindow.xaml` 中定义了 `TimeFormatConverter` 资源,以增强时间显示功能。 --- chatclient/App.xaml | 1 + chatclient/Data/ChatDataModel.cs | 23 ++++++++++------------- chatclient/MainWindow.xaml | 3 +++ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/chatclient/App.xaml b/chatclient/App.xaml index 768ad24..eed1546 100644 --- a/chatclient/App.xaml +++ b/chatclient/App.xaml @@ -3,6 +3,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:local="clr-namespace:chatclient" + xmlns:data="clr-namespace:chatclient.Data" StartupUri="MainWindow.xaml"> diff --git a/chatclient/Data/ChatDataModel.cs b/chatclient/Data/ChatDataModel.cs index af99423..69dbf2c 100644 --- a/chatclient/Data/ChatDataModel.cs +++ b/chatclient/Data/ChatDataModel.cs @@ -1,13 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Media; +using System.Windows.Media; using System.Windows; using System.Windows.Media.Imaging; -using System.Windows.Controls; -using System.Windows.Input; using System.Globalization; using System.Windows.Data; @@ -62,9 +55,6 @@ namespace chatclient.Data public string? UserName { get; set; } public string? UserPassword { get; set; } } - /// - /// 时间格式转换器类 - /// public class TimeFormatConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) @@ -81,7 +71,6 @@ namespace chatclient.Data } else if (timestamp.Kind == DateTimeKind.Unspecified) { - // 假设未指定时间是UTC时间(常见实践) localTime = DateTime.SpecifyKind(timestamp, DateTimeKind.Utc).ToLocalTime(); } else @@ -127,7 +116,15 @@ namespace chatclient.Data } return value; } - + /// + /// 将格式化的时间字符串转换回DateTime对象 + /// + /// + /// + /// + /// + /// + /// public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); diff --git a/chatclient/MainWindow.xaml b/chatclient/MainWindow.xaml index a81236f..144a7c0 100644 --- a/chatclient/MainWindow.xaml +++ b/chatclient/MainWindow.xaml @@ -10,6 +10,9 @@ mc:Ignorable="d" Title="ChatWindow" Height="450" Width="800" MinHeight="240" MinWidth="380" Style="{StaticResource MaterialDesignWindow}" Closed="MainWindow_Closed" Loaded="MainWindow_Loaded"> + + +