From 17a21424ac7203d26124323e712012c7a0fbfe93 Mon Sep 17 00:00:00 2001 From: ThomasGoulet73 Date: Tue, 2 Jan 2024 16:33:02 -0500 Subject: [PATCH 1/4] Use span for LengthConverter --- .../src/Common/src/MS/Internal/PixelUnit.cs | 75 +++++++++++++++++++ .../PresentationFramework.csproj | 1 + .../Controls/DataGridLengthConverter.cs | 40 +++------- .../System/Windows/LengthConverter.cs | 51 ++++--------- .../Markup/XamlFigureLengthSerializer.cs | 35 +++------ .../Markup/XamlGridLengthSerializer.cs | 38 +++------- 6 files changed, 126 insertions(+), 114 deletions(-) create mode 100644 src/Microsoft.DotNet.Wpf/src/Common/src/MS/Internal/PixelUnit.cs diff --git a/src/Microsoft.DotNet.Wpf/src/Common/src/MS/Internal/PixelUnit.cs b/src/Microsoft.DotNet.Wpf/src/Common/src/MS/Internal/PixelUnit.cs new file mode 100644 index 00000000000..e1e3b2c846a --- /dev/null +++ b/src/Microsoft.DotNet.Wpf/src/Common/src/MS/Internal/PixelUnit.cs @@ -0,0 +1,75 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; + +namespace MS.Internal +{ + internal readonly struct PixelUnit + { + public readonly string Name; + public readonly double Factor; + + private PixelUnit(string name, double factor) + { + Name = name; + Factor = factor; + } + + public static bool TryParsePixel(ReadOnlySpan value, out PixelUnit pixelUnit) + { + if (value.EndsWith("px", StringComparison.OrdinalIgnoreCase)) + { + pixelUnit = new PixelUnit("px", 1.0); + return true; + } + else + { + pixelUnit = default; + return false; + } + } + + public static bool TryParsePixelPerInch(ReadOnlySpan value, out PixelUnit pixelUnit) + { + if (value.EndsWith("in", StringComparison.OrdinalIgnoreCase)) + { + pixelUnit = new PixelUnit("in", 96.0); + return true; + } + else + { + pixelUnit = default; + return false; + } + } + + public static bool TryParsePixelPerCentimeter(ReadOnlySpan value, out PixelUnit pixelUnit) + { + if (value.EndsWith("cm", StringComparison.OrdinalIgnoreCase)) + { + pixelUnit = new PixelUnit("cm", 96.0 / 2.54); + return true; + } + else + { + pixelUnit = default; + return false; + } + } + + public static bool TryParsePixelPerPoint(ReadOnlySpan value, out PixelUnit pixelUnit) + { + if (value.EndsWith("pt", StringComparison.OrdinalIgnoreCase)) + { + pixelUnit = new PixelUnit("pt", 96.0 / 72.0); + return true; + } + else + { + pixelUnit = default; + return false; + } + } + } +} diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj index 91c17599028..c56715d1249 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj @@ -39,6 +39,7 @@ Common\System\SR.cs + diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridLengthConverter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridLengthConverter.cs index ed8cf2df1a2..c12da95dcd8 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridLengthConverter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridLengthConverter.cs @@ -196,14 +196,14 @@ internal static string ConvertToString(DataGridLength length, CultureInfo cultur /// private static DataGridLength ConvertFromString(string s, CultureInfo cultureInfo) { - string goodString = s.Trim().ToLowerInvariant(); + ReadOnlySpan valueSpan = s.AsSpan().Trim(); // Check if the string matches any of the descriptive unit types. // In these cases, there is no need to parse a value. for (int i = 0; i < NumDescriptiveUnits; i++) { string unitString = _unitStrings[i]; - if (goodString == unitString) + if (valueSpan.Equals(unitString, StringComparison.OrdinalIgnoreCase)) { return new DataGridLength(1.0, (DataGridLengthUnitType)i); } @@ -211,7 +211,6 @@ private static DataGridLength ConvertFromString(string s, CultureInfo cultureInf double value = 0.0; DataGridLengthUnitType unit = DataGridLengthUnitType.Pixel; - int strLen = goodString.Length; int strLenUnit = 0; double unitFactor = 1.0; @@ -223,7 +222,7 @@ private static DataGridLength ConvertFromString(string s, CultureInfo cultureInf // Note: This is NOT a culture specific comparison. // This is by design: we want the same unit string table to work across all cultures. - if (goodString.EndsWith(unitString, StringComparison.Ordinal)) + if (valueSpan.EndsWith(unitString, StringComparison.OrdinalIgnoreCase)) { strLenUnit = unitString.Length; unit = (DataGridLengthUnitType)i; @@ -234,24 +233,18 @@ private static DataGridLength ConvertFromString(string s, CultureInfo cultureInf // Couldn't match a standard unit type, try a non-standard unit type. if (strLenUnit == 0) { - numUnitStrings = _nonStandardUnitStrings.Length; - for (int i = 0; i < numUnitStrings; i++) + PixelUnit pixelUnit; + if (PixelUnit.TryParsePixelPerInch(valueSpan, out pixelUnit) + || PixelUnit.TryParsePixelPerCentimeter(valueSpan, out pixelUnit) + || PixelUnit.TryParsePixelPerPoint(valueSpan, out pixelUnit)) { - string unitString = _nonStandardUnitStrings[i]; - - // Note: This is NOT a culture specific comparison. - // This is by design: we want the same unit string table to work across all cultures. - if (goodString.EndsWith(unitString, StringComparison.Ordinal)) - { - strLenUnit = unitString.Length; - unitFactor = _pixelUnitFactors[i]; - break; - } + strLenUnit = pixelUnit.Name.Length; + unitFactor = pixelUnit.Factor; } } // Check if there is a numerical value to parse - if (strLen == strLenUnit) + if (valueSpan.Length == strLenUnit) { // There is no numerical value to parse if (unit == DataGridLengthUnitType.Star) @@ -267,7 +260,7 @@ private static DataGridLength ConvertFromString(string s, CultureInfo cultureInf (unit == DataGridLengthUnitType.Pixel) || DoubleUtil.AreClose(unitFactor, 1.0), "unitFactor should not be other than 1.0 unless the unit type is Pixel."); - ReadOnlySpan valueString = goodString.AsSpan(0, strLen - strLenUnit); + ReadOnlySpan valueString = valueSpan.Slice(0, valueSpan.Length - strLenUnit); value = double.Parse(valueString, provider: cultureInfo) * unitFactor; } @@ -276,16 +269,5 @@ private static DataGridLength ConvertFromString(string s, CultureInfo cultureInf private static string[] _unitStrings = { "auto", "px", "sizetocells", "sizetoheader", "*" }; private const int NumDescriptiveUnits = 3; - - // This array contains strings for unit types not included in the standard set - private static string[] _nonStandardUnitStrings = { "in", "cm", "pt" }; - - // These are conversion factors to transform other units to pixels - private static double[] _pixelUnitFactors = - { - 96.0, // Pixels per Inch - 96.0 / 2.54, // Pixels per Centimeter - 96.0 / 72.0, // Pixels per Point - }; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/LengthConverter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/LengthConverter.cs index 556cd829eb1..e0cedb5ac8f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/LengthConverter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/LengthConverter.cs @@ -181,60 +181,41 @@ public override object ConvertTo(ITypeDescriptorContext typeDescriptorContext, // NOTE - This code is called from FontSizeConverter, so changes will affect both. static internal double FromString(string s, CultureInfo cultureInfo) { - string valueString = s.Trim(); - string goodString = valueString.ToLowerInvariant(); - int strLen = goodString.Length; - int strLenUnit = 0; + ReadOnlySpan valueSpan = s.AsSpan().Trim(); double unitFactor = 1.0; //Auto is represented and Double.NaN //properties that do not want Auto and NaN to be in their ligit values, //should disallow NaN in validation callbacks (same goes for negative values) - if (goodString == "auto") return Double.NaN; - - for (int i = 0; i < PixelUnitStrings.Length; i++) + if (valueSpan.Equals("auto", StringComparison.OrdinalIgnoreCase)) + return Double.NaN; + + PixelUnit pixelUnit; + if (PixelUnit.TryParsePixel(valueSpan, out pixelUnit) + || PixelUnit.TryParsePixelPerInch(valueSpan, out pixelUnit) + || PixelUnit.TryParsePixelPerCentimeter(valueSpan, out pixelUnit) + || PixelUnit.TryParsePixelPerPoint(valueSpan, out pixelUnit)) { - // NOTE: This is NOT a culture specific comparison. - // This is by design: we want the same unit string table to work across all cultures. - if (goodString.EndsWith(PixelUnitStrings[i], StringComparison.Ordinal)) - { - strLenUnit = PixelUnitStrings[i].Length; - unitFactor = PixelUnitFactors[i]; - break; - } + valueSpan = valueSpan.Slice(0, valueSpan.Length - pixelUnit.Name.Length); + unitFactor = pixelUnit.Factor; } - // important to substring original non-lowered string - // this allows case sensitive ToDouble below handle "NaN" and "Infinity" correctly. - // this addresses windows bug 1177408 - valueString = valueString.Substring(0, strLen - strLenUnit); + if (valueSpan.IsEmpty) + return 0; - // FormatException errors thrown by Convert.ToDouble are pretty uninformative. + // FormatException errors thrown by double.Parse are pretty uninformative. // Throw a more meaningful error in this case that tells that we were attempting // to create a Length instance from a string. This addresses windows bug 968884 try { - double result = Convert.ToDouble(valueString, cultureInfo) * unitFactor; - return result; + return double.Parse(valueSpan, cultureInfo) * unitFactor; } catch (FormatException) { - throw new FormatException(SR.Format(SR.LengthFormatError, valueString)); + throw new FormatException(SR.Format(SR.LengthFormatError, valueSpan.ToString())); } } - // This array contains strings for unit types - // These are effectively "TypeConverter only" units. - // They are all expressable in terms of the Pixel unit type and a conversion factor. - static private string[] PixelUnitStrings = { "px", "in", "cm", "pt" }; - static private double[] PixelUnitFactors = - { - 1.0, // Pixel itself - 96.0, // Pixels per Inch - 96.0 / 2.54, // Pixels per Centimeter - 96.0 / 72.0, // Pixels per Point - }; - static internal string ToString(double l, CultureInfo cultureInfo) { if(double.IsNaN(l)) return "Auto"; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlFigureLengthSerializer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlFigureLengthSerializer.cs index eaee23b25e9..ccf1843b797 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlFigureLengthSerializer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlFigureLengthSerializer.cs @@ -186,13 +186,12 @@ static internal void FromString( out double value, out FigureUnitType unit) { - string goodString = s.Trim().ToLowerInvariant(); + ReadOnlySpan valueSpan = s.Trim().AsSpan(); value = 0.0; unit = FigureUnitType.Pixel; int i; - int strLen = goodString.Length; int strLenUnit = 0; double unitFactor = 1.0; @@ -200,7 +199,7 @@ static internal void FromString( // peel [unit] off the end of the string i = 0; - if (goodString == UnitStrings[i].Name) + if (valueSpan.Equals(UnitStrings[i].Name, StringComparison.OrdinalIgnoreCase)) { strLenUnit = UnitStrings[i].Name.Length; unit = UnitStrings[i].UnitType; @@ -211,7 +210,7 @@ static internal void FromString( { // Note: this is NOT a culture specific comparison. // this is by design: we want the same unit string table to work across all cultures. - if (goodString.EndsWith(UnitStrings[i].Name, StringComparison.Ordinal)) + if (valueSpan.EndsWith(UnitStrings[i].Name, StringComparison.Ordinal)) { strLenUnit = UnitStrings[i].Name.Length; unit = UnitStrings[i].UnitType; @@ -224,23 +223,20 @@ static internal void FromString( // try again with a converter-only unit (a pixel equivalent). if (i >= UnitStrings.Length) { - for (i = 0; i < PixelUnitStrings.Length; ++i) + PixelUnit pixelUnit; + if (PixelUnit.TryParsePixelPerInch(valueSpan, out pixelUnit) + || PixelUnit.TryParsePixelPerCentimeter(valueSpan, out pixelUnit) + || PixelUnit.TryParsePixelPerPoint(valueSpan, out pixelUnit)) { - // Note: this is NOT a culture specific comparison. - // this is by design: we want the same unit string table to work across all cultures. - if (goodString.EndsWith(PixelUnitStrings[i], StringComparison.Ordinal)) - { - strLenUnit = PixelUnitStrings[i].Length; - unitFactor = PixelUnitFactors[i]; - break; - } + strLenUnit = pixelUnit.Name.Length; + unitFactor = pixelUnit.Factor; } } // this is where we would handle leading whitespace on the input string. // this is also where we would handle whitespace between [value] and [unit]. // check if we don't have a [value]. This is acceptable for certain UnitTypes. - if (strLen == strLenUnit && unit != FigureUnitType.Pixel) + if (valueSpan.Length == strLenUnit && unit != FigureUnitType.Pixel) { value = 1; @@ -251,7 +247,7 @@ static internal void FromString( Debug.Assert( unit == FigureUnitType.Pixel || DoubleUtil.AreClose(unitFactor, 1.0) ); - ReadOnlySpan valueString = goodString.AsSpan(0, strLen - strLenUnit); + ReadOnlySpan valueString = valueSpan.Slice(0, valueSpan.Length - strLenUnit); value = double.Parse(valueString, provider: cultureInfo) * unitFactor; } } @@ -283,15 +279,6 @@ internal FigureUnitTypeStringConvert(string name, FigureUnitType unitType) new FigureUnitTypeStringConvert("page", FigureUnitType.Page) }; - // this array contains strings for unit types that are not present in the FigureUnitType enum - static private string[] PixelUnitStrings = { "in", "cm", "pt" }; - static private double[] PixelUnitFactors = - { - 96.0, // Pixels per Inch - 96.0 / 2.54, // Pixels per Centimeter - 96.0 / 72.0, // Pixels per Point - }; - #endregion Fields } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlGridLengthSerializer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlGridLengthSerializer.cs index 4035876de60..7c4da807a67 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlGridLengthSerializer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlGridLengthSerializer.cs @@ -187,13 +187,12 @@ static internal void FromString( out double value, out GridUnitType unit) { - string goodString = s.Trim().ToLowerInvariant(); + ReadOnlySpan valueSpan = s.Trim().AsSpan(); value = 0.0; unit = GridUnitType.Pixel; int i; - int strLen = goodString.Length; int strLenUnit = 0; double unitFactor = 1.0; @@ -201,7 +200,7 @@ static internal void FromString( // peel [unit] off the end of the string i = 0; - if (goodString == UnitStrings[i]) + if (valueSpan.Equals(UnitStrings[i], StringComparison.OrdinalIgnoreCase)) { strLenUnit = UnitStrings[i].Length; unit = (GridUnitType)i; @@ -212,7 +211,7 @@ static internal void FromString( { // Note: this is NOT a culture specific comparison. // this is by design: we want the same unit string table to work across all cultures. - if (goodString.EndsWith(UnitStrings[i], StringComparison.Ordinal)) + if (valueSpan.EndsWith(UnitStrings[i], StringComparison.OrdinalIgnoreCase)) { strLenUnit = UnitStrings[i].Length; unit = (GridUnitType)i; @@ -225,25 +224,21 @@ static internal void FromString( // try again with a converter-only unit (a pixel equivalent). if (i >= UnitStrings.Length) { - for (i = 0; i < PixelUnitStrings.Length; ++i) + PixelUnit pixelUnit; + if (PixelUnit.TryParsePixelPerInch(valueSpan, out pixelUnit) + || PixelUnit.TryParsePixelPerCentimeter(valueSpan, out pixelUnit) + || PixelUnit.TryParsePixelPerPoint(valueSpan, out pixelUnit)) { - // Note: this is NOT a culture specific comparison. - // this is by design: we want the same unit string table to work across all cultures. - if (goodString.EndsWith(PixelUnitStrings[i], StringComparison.Ordinal)) - { - strLenUnit = PixelUnitStrings[i].Length; - unitFactor = PixelUnitFactors[i]; - break; - } + strLenUnit = pixelUnit.Name.Length; + unitFactor = pixelUnit.Factor; } } // this is where we would handle leading whitespace on the input string. // this is also where we would handle whitespace between [value] and [unit]. // check if we don't have a [value]. This is acceptable for certain UnitTypes. - if ( strLen == strLenUnit - && ( unit == GridUnitType.Auto - || unit == GridUnitType.Star ) ) + if (valueSpan.Length == strLenUnit + && unit is GridUnitType.Auto or GridUnitType.Star) { value = 1; } @@ -253,7 +248,7 @@ static internal void FromString( Debug.Assert( unit == GridUnitType.Pixel || DoubleUtil.AreClose(unitFactor, 1.0) ); - ReadOnlySpan valueString = goodString.AsSpan(0, strLen - strLenUnit); + ReadOnlySpan valueString = valueSpan.Slice(0, valueSpan.Length - strLenUnit); value = double.Parse(valueString, provider: cultureInfo) * unitFactor; } } @@ -266,15 +261,6 @@ static internal void FromString( // Note: keep this array in sync with the GridUnitType enum static private string[] UnitStrings = { "auto", "px", "*" }; - // this array contains strings for unit types that are not present in the GridUnitType enum - static private string[] PixelUnitStrings = { "in", "cm", "pt" }; - static private double[] PixelUnitFactors = - { - 96.0, // Pixels per Inch - 96.0 / 2.54, // Pixels per Centimeter - 96.0 / 72.0, // Pixels per Point - }; - #endregion Fields } } From 8ea913b2f0e29f8d82d2bcd23dcc555996abc7d7 Mon Sep 17 00:00:00 2001 From: ThomasGoulet73 Date: Wed, 10 Jan 2024 23:36:59 -0500 Subject: [PATCH 2/4] Fix slight regression --- .../System/Windows/LengthConverter.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/LengthConverter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/LengthConverter.cs index e0cedb5ac8f..0b955bbb1dd 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/LengthConverter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/LengthConverter.cs @@ -203,16 +203,21 @@ static internal double FromString(string s, CultureInfo cultureInfo) if (valueSpan.IsEmpty) return 0; + return ParseDouble(valueSpan, cultureInfo) * unitFactor; + } + + private static double ParseDouble(ReadOnlySpan span, CultureInfo cultureInfo) + { // FormatException errors thrown by double.Parse are pretty uninformative. // Throw a more meaningful error in this case that tells that we were attempting // to create a Length instance from a string. This addresses windows bug 968884 try { - return double.Parse(valueSpan, cultureInfo) * unitFactor; + return double.Parse(span, cultureInfo); } catch (FormatException) { - throw new FormatException(SR.Format(SR.LengthFormatError, valueSpan.ToString())); + throw new FormatException(SR.Format(SR.LengthFormatError, span.ToString())); } } From 0de07db3d513b3a2c56c01053bf0cbb0c0f4259e Mon Sep 17 00:00:00 2001 From: ThomasGoulet73 Date: Thu, 22 Aug 2024 23:31:31 -0400 Subject: [PATCH 3/4] PR Feedback --- .../src/PresentationFramework/PresentationFramework.csproj | 4 +++- .../System/Windows/Markup/XamlFigureLengthSerializer.cs | 2 +- .../System/Windows/Markup/XamlGridLengthSerializer.cs | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj index fc3b4e8148f..9d00dcdc2a6 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj @@ -38,7 +38,9 @@ Common\System\SR.cs - + + MS\Internal\PixelUnit.cs + diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlFigureLengthSerializer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlFigureLengthSerializer.cs index ccf1843b797..dc2de08b410 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlFigureLengthSerializer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlFigureLengthSerializer.cs @@ -186,7 +186,7 @@ static internal void FromString( out double value, out FigureUnitType unit) { - ReadOnlySpan valueSpan = s.Trim().AsSpan(); + ReadOnlySpan valueSpan = s.AsSpan().Trim(); value = 0.0; unit = FigureUnitType.Pixel; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlGridLengthSerializer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlGridLengthSerializer.cs index 7c4da807a67..b9b1816c1fa 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlGridLengthSerializer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlGridLengthSerializer.cs @@ -187,7 +187,7 @@ static internal void FromString( out double value, out GridUnitType unit) { - ReadOnlySpan valueSpan = s.Trim().AsSpan(); + ReadOnlySpan valueSpan = s.AsSpan().Trim(); value = 0.0; unit = GridUnitType.Pixel; From 14e736c9832d826e0939407cc8abe3c3773f8db5 Mon Sep 17 00:00:00 2001 From: ThomasGoulet73 Date: Sat, 14 Sep 2024 01:33:07 -0400 Subject: [PATCH 4/4] Fix string comparison --- .../System/Windows/Markup/XamlFigureLengthSerializer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlFigureLengthSerializer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlFigureLengthSerializer.cs index dc2de08b410..6f864371bfb 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlFigureLengthSerializer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlFigureLengthSerializer.cs @@ -210,7 +210,7 @@ static internal void FromString( { // Note: this is NOT a culture specific comparison. // this is by design: we want the same unit string table to work across all cultures. - if (valueSpan.EndsWith(UnitStrings[i].Name, StringComparison.Ordinal)) + if (valueSpan.EndsWith(UnitStrings[i].Name, StringComparison.OrdinalIgnoreCase)) { strLenUnit = UnitStrings[i].Name.Length; unit = UnitStrings[i].UnitType;