2025-07-31 20:12:24 +08:00
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
using System.Windows.Data;
|
|
|
|
|
|
|
2026-01-02 17:30:41 +08:00
|
|
|
|
namespace Melskin.Converters.Internal;
|
2025-08-12 23:08:54 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 将光强度值转换为灯光边距的转换器。该转换器实现了 IValueConverter 接口,用于将双精度浮点数表示的光强度值转换成 Thickness 类型的对象,代表了灯光效果在用户界面中的边距。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// 该转换器主要用于 WPF 应用程序中,通过绑定到 UI 元素上,实现基于光强度动态调整边距的效果。它不支持从 Thickness 转换回光强度的逆向操作。
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
[ValueConversion(typeof(double), typeof(Thickness))]
|
|
|
|
|
|
internal class IntensityToSlotLightMarginConverter : IValueConverter
|
2025-07-31 20:12:24 +08:00
|
|
|
|
{
|
2025-08-12 23:08:54 +08:00
|
|
|
|
public static readonly IntensityToSlotLightMarginConverter Instance = new();
|
2025-08-20 12:10:13 +08:00
|
|
|
|
|
2025-08-12 23:08:54 +08:00
|
|
|
|
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
|
|
|
|
{
|
|
|
|
|
|
var intensity = (double)(value ?? 0);
|
|
|
|
|
|
//此处与中央Margin匹配
|
|
|
|
|
|
var offset = 4 + intensity * 4;
|
2025-08-20 12:10:13 +08:00
|
|
|
|
return new Thickness(offset, offset, 0, 0);
|
2025-08-12 23:08:54 +08:00
|
|
|
|
}
|
2025-07-31 20:12:24 +08:00
|
|
|
|
|
2025-08-12 23:08:54 +08:00
|
|
|
|
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
|
|
|
|
{
|
2025-08-20 12:10:13 +08:00
|
|
|
|
return Binding.DoNothing;
|
2025-07-31 20:12:24 +08:00
|
|
|
|
}
|
2025-08-12 23:08:54 +08:00
|
|
|
|
}
|