Files
ShrlAlgoToolkit/AntdWpf/Utils/UIElementUtil.cs
ShrlAlgo 4d35cadb56 更新
2025-07-11 09:20:23 +08:00

32 lines
918 B
C#

namespace AntdWpf.Utils
{
using System;
public static class UIElementUtil
{
public static double RoundLayoutValue(double value, double dpiScale)
{
double newValue;
// If DPI == 1, don't use DPI-aware rounding.
if (!DoubleUtil.AreClose(dpiScale, 1.0))
{
newValue = Math.Round(value * dpiScale) / dpiScale;
// If rounding produces a value unacceptable to layout (NaN, Infinity or MaxValue), use the original value.
if (double.IsNaN(newValue) ||
double.IsInfinity(newValue) ||
DoubleUtil.AreClose(newValue, double.MaxValue))
{
newValue = value;
}
}
else
{
newValue = Math.Round(value);
}
return newValue;
}
}
}