From 690a7b587a7499184b982f03eb94bfcff8b755c0 Mon Sep 17 00:00:00 2001 From: xyy <544939200@qq.com> Date: Sun, 12 Apr 2026 20:22:21 +0800 Subject: [PATCH] --- Models/TestLiquid.cs | 20 ++++++++++++++++-- ViewModels/BubblePointViewModel.cs | 2 +- ViewModels/PoreDistributionViewModel.cs | 27 ++++++++++++++++++++++++- Views/PoreDistributionView.xaml.cs | 4 ++-- 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/Models/TestLiquid.cs b/Models/TestLiquid.cs index 88d7f05..ea6d03b 100644 --- a/Models/TestLiquid.cs +++ b/Models/TestLiquid.cs @@ -1,6 +1,6 @@ namespace MembranePoreTester.Models { - public class TestLiquid + public class TestLiquid : IEquatable { public string Name { get; set; } public double SurfaceTension { get; set; } // mN/m, 25°C @@ -10,7 +10,7 @@ public double C_cmHg => 2.15 * SurfaceTension; public double C_psi => 0.415 * SurfaceTension; - public static List Predefined => new() + private static readonly List _predefined = new() { new TestLiquid { Name = "水", SurfaceTension = 72.0 }, new TestLiquid { Name = "石油馏分", SurfaceTension = 30.0 }, @@ -18,5 +18,21 @@ new TestLiquid { Name = "液态石蜡", SurfaceTension = 34.7 }, new TestLiquid { Name = "BSD16", SurfaceTension = 16.0 } // 新增 }; + + // 返回可修改的全局液体列表(允许在运行时添加自定义液体便于恢复选择) + public static List Predefined => _predefined; + + public override string ToString() => Name; + + public bool Equals(TestLiquid other) + { + if (other is null) return false; + // 以 Name 为主键判断相等,SurfaceTension 可作为辅助信息 + return string.Equals(Name, other.Name, StringComparison.Ordinal); + } + + public override bool Equals(object obj) => Equals(obj as TestLiquid); + + public override int GetHashCode() => Name?.GetHashCode() ?? 0; } } \ No newline at end of file diff --git a/ViewModels/BubblePointViewModel.cs b/ViewModels/BubblePointViewModel.cs index 28d2b08..920ce22 100644 --- a/ViewModels/BubblePointViewModel.cs +++ b/ViewModels/BubblePointViewModel.cs @@ -42,7 +42,7 @@ namespace MembranePoreTester.ViewModels }); } - public List Liquids => TestLiquid.Predefined; + public IReadOnlyList Liquids => TestLiquid.Predefined; public List PressureUnits => new() { "Pa", "cmHg", "psi" }; public List MembraneTypes => new() { "平板膜", "中空纤维膜" }; diff --git a/ViewModels/PoreDistributionViewModel.cs b/ViewModels/PoreDistributionViewModel.cs index 1dc59f2..da29ddd 100644 --- a/ViewModels/PoreDistributionViewModel.cs +++ b/ViewModels/PoreDistributionViewModel.cs @@ -243,11 +243,22 @@ namespace MembranePoreTester.ViewModels { // 当 Record 替换时(例如从数据库加载),重新订阅其 DataPoints 集合 HookDataPointsCollection(_record?.DataPoints); + + // 同步液体选择 + if (_record?.Liquid != null) + { + var matchedLiquid = Liquids.FirstOrDefault(l => l.Name == _record.Liquid.Name); + SelectedLiquid = matchedLiquid ?? _record.Liquid; + } + else + { + SelectedLiquid = Liquids.FirstOrDefault(); + } } } } - public List Liquids => TestLiquid.Predefined; + public IReadOnlyList Liquids => TestLiquid.Predefined; public List PressureUnits => new() { "Pa", "cmHg", "psi" }; public List MembraneTypes => new() { "平板膜", "中空纤维膜" }; @@ -944,6 +955,20 @@ namespace MembranePoreTester.ViewModels }); } + // 同步液体选择 + if (Record.Liquid != null) + { + var matchedLiquid = Liquids.FirstOrDefault(l => l.Name == Record.Liquid.Name); + SelectedLiquid = matchedLiquid ?? Record.Liquid; + } + else + { + SelectedLiquid = Liquids.FirstOrDefault(); + } + + + + // 重新计算平均孔径和分布(触发计算命令) Calculate(); } diff --git a/Views/PoreDistributionView.xaml.cs b/Views/PoreDistributionView.xaml.cs index ad25b6c..72f3979 100644 --- a/Views/PoreDistributionView.xaml.cs +++ b/Views/PoreDistributionView.xaml.cs @@ -95,8 +95,8 @@ namespace MembranePoreTester.Views { if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) { - ScrollDataGridToEnd(dgWetData); - ScrollDataGridToEnd(dgDryData); + //ScrollDataGridToEnd(dgWetData); + //ScrollDataGridToEnd(dgDryData); } }