namespace AntDesign.WPF.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; } } }