Files
ShrlAlgoToolkit/Melskin/Converters/Internal/IntensityToEmbossMarginLeftTopConverter.cs
2026-02-17 22:17:13 +08:00

27 lines
1.2 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Globalization;
using System.Windows.Data;
namespace Melskin.Converters.Internal;
/// <summary>
/// 将浮点数类型的强度值转换为左上边距的 Thickness 对象。该转换器适用于需要根据浮点数值动态调整 UI 元素边距的场景。
/// 当输入的强度值为 1 时,生成的边距最小,随着强度值减小,边距逐渐增大,从而影响 UI 元素显示效果,如阴影或光照效果的范围。
/// </summary>
[ValueConversion(typeof(double), typeof(Thickness))]
internal class IntensityToEmbossMarginLeftTopConverter : IValueConverter
{
public static readonly IntensityToEmbossMarginLeftTopConverter Instance = new();
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
var intensity = (double)(value ?? 0.5);
//数值为1的时候边距最小露出的着色边框越大
var marginValue = 2 * intensity;
return new Thickness(-marginValue, -marginValue, marginValue, marginValue);
}
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return Binding.DoNothing;
}
}