diff --git a/CSI-H238M/CSI-H238M/App.xaml.cs b/CSI-H238M/CSI-H238M/App.xaml.cs
index 19c1eb6..12b5256 100644
--- a/CSI-H238M/CSI-H238M/App.xaml.cs
+++ b/CSI-H238M/CSI-H238M/App.xaml.cs
@@ -22,6 +22,9 @@ namespace CSI_H238M
try
{
+ // 在應用啟動時設置 ScottPlot 的中文字體(必須最先執行)
+ SetScottPlotChineseFont();
+
// 加載應用程序配置
string configPath = AppConfig.GetDefaultConfigPath();
_config = AppConfig.Load(configPath);
@@ -47,6 +50,44 @@ namespace CSI_H238M
}
}
+ ///
+ /// 設置 ScottPlot 的中文字體
+ ///
+ private void SetScottPlotChineseFont()
+ {
+ try
+ {
+ // 使用 SkiaSharp 的字體管理器查找支持中文的字體
+ var fontManager = SkiaSharp.SKFontManager.Default;
+
+ // 嘗試匹配一個中文字符來找到合適的字體
+ var typeface = fontManager.MatchCharacter('中');
+ if (typeface != null && !string.IsNullOrEmpty(typeface.FamilyName))
+ {
+ ScottPlot.Fonts.Default = typeface.FamilyName;
+ System.Diagnostics.Debug.WriteLine($"[App] 使用系統中文字體: {typeface.FamilyName}");
+ return;
+ }
+
+ // 備選方案:嘗試常見的中文字體名稱
+ var chineseFonts = new[] { "Microsoft YaHei", "SimHei", "SimSun" };
+ foreach (var fontName in chineseFonts)
+ {
+ var tf = SkiaSharp.SKTypeface.FromFamilyName(fontName);
+ if (tf != null)
+ {
+ ScottPlot.Fonts.Default = fontName;
+ System.Diagnostics.Debug.WriteLine($"[App] 使用中文字體: {fontName}");
+ return;
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"[App] 設置中文字體失敗: {ex.Message}");
+ }
+ }
+
///
/// 根據配置創建相應的數據採集服務
///
diff --git a/CSI-H238M/CSI-H238M/Resources/LanguageResources.cs b/CSI-H238M/CSI-H238M/Resources/LanguageResources.cs
index 03f76ff..57793ee 100644
--- a/CSI-H238M/CSI-H238M/Resources/LanguageResources.cs
+++ b/CSI-H238M/CSI-H238M/Resources/LanguageResources.cs
@@ -32,6 +32,8 @@ namespace COFTester.Resources
["StartTest"] = "开始测试",
["Stop"] = "停止",
["ResetSystem"] = "重置系统",
+ ["Connect"] = "连接",
+ ["Disconnect"] = "断开",
// 左侧面板 - 测试参数
["TestParameters"] = "测试参数",
@@ -57,6 +59,7 @@ namespace COFTester.Resources
// 右侧面板 - 统计信息
["Statistics"] = "统计信息",
["GroupStatistics"] = "成组统计",
+ ["CurrentTest"] = "当前测试",
["AvgForce"] = "平均力值:",
["TestTime"] = "测试时间:",
["DataPoints"] = "数据点数:",
@@ -67,6 +70,9 @@ namespace COFTester.Resources
["Status"] = "状态:",
["PLCConnected"] = "PLC: 已连接",
["DataPointsCount"] = "数据点: {0}",
+ ["Connected"] = "已连接",
+ ["NotConnected"] = "未连接",
+ ["Connecting"] = "连接中...",
// 状态消息
["SystemReady"] = "系统就绪",
@@ -119,6 +125,8 @@ namespace COFTester.Resources
["StartTest"] = "Start Test",
["Stop"] = "Stop",
["ResetSystem"] = "Reset System",
+ ["Connect"] = "Connect",
+ ["Disconnect"] = "Disconnect",
// Left Panel - Test Parameters
["TestParameters"] = "Test Parameters",
@@ -144,6 +152,7 @@ namespace COFTester.Resources
// Right Panel - Statistics
["Statistics"] = "Statistics",
["GroupStatistics"] = "Group Statistics",
+ ["CurrentTest"] = "Current Test",
["AvgForce"] = "Avg Force:",
["TestTime"] = "Test Time:",
["DataPoints"] = "Data Points:",
@@ -154,6 +163,9 @@ namespace COFTester.Resources
["Status"] = "Status:",
["PLCConnected"] = "PLC: Connected",
["DataPointsCount"] = "Data Points: {0}",
+ ["Connected"] = "Connected",
+ ["NotConnected"] = "Not Connected",
+ ["Connecting"] = "Connecting...",
// Status Messages
["SystemReady"] = "System Ready",
@@ -240,6 +252,12 @@ namespace COFTester.Resources
public string Status => GetString("Status");
public string PLCConnected => GetString("PLCConnected");
public string DataPointsCount => GetString("DataPointsCount");
+ public string Connected => GetString("Connected");
+ public string NotConnected => GetString("NotConnected");
+ public string Connecting => GetString("Connecting");
+ public string Connect => GetString("Connect");
+ public string Disconnect => GetString("Disconnect");
+ public string CurrentTest => GetString("CurrentTest");
public string SystemReady => GetString("SystemReady");
public string Testing => GetString("Testing");
public string TestStopped => GetString("TestStopped");
@@ -325,6 +343,12 @@ namespace COFTester.Resources
OnPropertyChanged(nameof(Status));
OnPropertyChanged(nameof(PLCConnected));
OnPropertyChanged(nameof(DataPointsCount));
+ OnPropertyChanged(nameof(Connected));
+ OnPropertyChanged(nameof(NotConnected));
+ OnPropertyChanged(nameof(Connecting));
+ OnPropertyChanged(nameof(Connect));
+ OnPropertyChanged(nameof(Disconnect));
+ OnPropertyChanged(nameof(CurrentTest));
OnPropertyChanged(nameof(SystemReady));
OnPropertyChanged(nameof(Testing));
OnPropertyChanged(nameof(TestStopped));
diff --git a/CSI-H238M/CSI-H238M/ViewModels/ViewModel.cs b/CSI-H238M/CSI-H238M/ViewModels/ViewModel.cs
index 4b22132..a043ed6 100644
--- a/CSI-H238M/CSI-H238M/ViewModels/ViewModel.cs
+++ b/CSI-H238M/CSI-H238M/ViewModels/ViewModel.cs
@@ -107,7 +107,7 @@ namespace COFTester.ViewModels
{
_wpfPlot.Plot.Clear();
- // 设置支持中文的字体
+ // 设置支持中文的字体(必须在添加任何元素之前)
SetChineseFont();
// 创建空的散点图
@@ -116,7 +116,7 @@ namespace COFTester.ViewModels
_scatterPlot.LineWidth = 2;
_scatterPlot.MarkerSize = 0;
- // 设置坐标轴标签
+ // 设置坐标轴标签(使用已设置的中文字体)
_wpfPlot.Plot.XLabel(Lang.DisplacementAxis);
_wpfPlot.Plot.YLabel(Lang.ForceAxis);
@@ -138,24 +138,39 @@ namespace COFTester.ViewModels
{
try
{
- // 尝试使用常见的中文字体
- // Windows 系统通常有这些字体:Microsoft YaHei, SimHei, SimSun
- var availableFonts = new[] { "Microsoft YaHei", "SimHei", "SimSun", "Arial Unicode MS" };
+ // 方法1: 使用 SkiaSharp 的字体管理器查找支持中文的字体
+ var fontManager = SkiaSharp.SKFontManager.Default;
- foreach (var font in availableFonts)
+ // 尝试匹配一个中文字符来找到合适的字体
+ var typeface = fontManager.MatchCharacter('中');
+ if (typeface != null && !string.IsNullOrEmpty(typeface.FamilyName))
{
- try
+ ScottPlot.Fonts.Default = typeface.FamilyName;
+ System.Diagnostics.Debug.WriteLine($"使用系统中文字体: {typeface.FamilyName}");
+ return;
+ }
+
+ // 方法2: 尝试常见的中文字体名称
+ var chineseFonts = new[]
+ {
+ "Microsoft YaHei", // 微软雅黑
+ "SimHei", // 黑体
+ "SimSun", // 宋体
+ "Microsoft YaHei UI", // 微软雅黑 UI
+ "DengXian", // 等线
+ };
+
+ foreach (var fontName in chineseFonts)
+ {
+ var tf = SkiaSharp.SKTypeface.FromFamilyName(fontName);
+ if (tf != null && tf.FamilyName == fontName)
{
- _wpfPlot.Plot.Font.Set(font);
- return; // 成功设置字体后退出
- }
- catch
- {
- continue; // 尝试下一个字体
+ ScottPlot.Fonts.Default = fontName;
+ System.Diagnostics.Debug.WriteLine($"成功设置中文字体: {fontName}");
+ return;
}
}
- // 如果所有字体都失败,使用默认字体(可能显示方框)
System.Diagnostics.Debug.WriteLine("警告:无法找到支持中文的字体");
}
catch (Exception ex)
@@ -844,13 +859,16 @@ namespace COFTester.ViewModels
}
}
- public event EventHandler? CanExecuteChanged;
+ public event EventHandler? CanExecuteChanged
+ {
+ add { CommandManager.RequerySuggested += value; }
+ remove { CommandManager.RequerySuggested -= value; }
+ }
private void RaiseCanExecuteChanged()
{
Application.Current?.Dispatcher.InvokeAsync(() =>
{
- CanExecuteChanged?.Invoke(this, EventArgs.Empty);
CommandManager.InvalidateRequerySuggested();
});
}
diff --git a/CSI-H238M/CSI-H238M/Views/MainWindow.xaml b/CSI-H238M/CSI-H238M/Views/MainWindow.xaml
index b77b9a9..2133a52 100644
--- a/CSI-H238M/CSI-H238M/Views/MainWindow.xaml
+++ b/CSI-H238M/CSI-H238M/Views/MainWindow.xaml
@@ -151,7 +151,7 @@
-