diff --git a/Shared/General/Logger.cs b/Shared/General/Logger.cs
index d9ef7b3..f229c9b 100644
--- a/Shared/General/Logger.cs
+++ b/Shared/General/Logger.cs
@@ -56,7 +56,7 @@ public enum LogBehavior {
}
public static class Logger {
- internal static BaseLogger Instance { get; set; } = new();
+ public static BaseLogger Instance { get; set; } = new();
// 转发给实例的方法包装
public static void Log(string message, LogLevel level = LogLevel.Info, LogBehavior behavior = LogBehavior.None, [CallerFilePath] string filePath = "")
diff --git a/Wpf/General/ValueConverters.cs b/Wpf/General/ValueConverters.cs
new file mode 100644
index 0000000..a8f98f6
--- /dev/null
+++ b/Wpf/General/ValueConverters.cs
@@ -0,0 +1,74 @@
+using System.Globalization;
+using System.Windows;
+using System.Windows.Data;
+
+namespace MeloongCore.Wpf;
+
+///
+/// 对数据绑定进行加法运算,使用 决定加数。
+///
+public class AdditionConverter : IValueConverter {
+ public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) {
+ if (value is null) return 0;
+ if (!double.TryParse(value.ToString(), out double before)) return 0;
+ double scale = 1;
+ if (parameter is not null) double.TryParse(parameter.ToString(), out scale);
+ return before + scale;
+ }
+ public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) {
+ if (value is null) return Binding.DoNothing;
+ if (!double.TryParse(value.ToString(), out double before)) return Binding.DoNothing;
+ double scale = 1;
+ if (parameter is not null) double.TryParse(parameter.ToString(), out scale);
+ return before - scale;
+ }
+}
+
+///
+/// 对数据绑定进行乘法运算,使用 决定乘数。
+///
+public class MultiplicationConverter : IValueConverter {
+ public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) {
+ if (value is null) return 0;
+ if (!double.TryParse(value.ToString(), out double before)) return 0;
+ double scale = 1;
+ if (parameter is not null) double.TryParse(parameter.ToString(), out scale);
+ return before * scale;
+ }
+ public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) {
+ if (value is null) return Binding.DoNothing;
+ if (!double.TryParse(value.ToString(), out double before)) return Binding.DoNothing;
+ double scale = 1;
+ if (parameter is not null) double.TryParse(parameter.ToString(), out scale);
+ if (scale == 0) return Binding.DoNothing;
+ return before / scale;
+ }
+}
+
+///
+/// 将取反的 绑定到 。
+///
+public class InverseBooleanToVisibilityConverter : IValueConverter {
+ public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) {
+ if (value is null) return Visibility.Visible;
+ return bool.TryParse(value.ToString(), out bool boolValue) ? (boolValue ? Visibility.Collapsed : Visibility.Visible) : Visibility.Visible;
+ }
+ public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) {
+ if (value is null) return false;
+ return value is Visibility vis && vis != Visibility.Visible;
+ }
+}
+
+///
+/// 将 取反。
+///
+public class InverseBooleanConverter : IValueConverter {
+ public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) {
+ if (value is null) return false;
+ return bool.TryParse(value.ToString(), out bool boolValue) ? !boolValue : false;
+ }
+ public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) {
+ if (value is null) return false;
+ return bool.TryParse(value.ToString(), out bool boolValue) ? !boolValue : false;
+ }
+}
\ No newline at end of file
diff --git a/Wpf/MeloongCore.Wpf.csproj b/Wpf/MeloongCore.Wpf.csproj
index f11c0ec..648c72f 100644
--- a/Wpf/MeloongCore.Wpf.csproj
+++ b/Wpf/MeloongCore.Wpf.csproj
@@ -38,6 +38,7 @@
+