Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Binding convert looks at right culture setting #15240

Merged
merged 2 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Xamarin.Forms.Core.UnitTests/BindingExpressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void ValidPaths(
[TestCaseSource(nameof(TryConvertWithNumbersAndCulturesCases))]
public void TryConvertWithNumbersAndCultures(object inputString, CultureInfo culture, object expected)
{
CultureInfo.CurrentUICulture = culture;
CultureInfo.CurrentCulture = culture;
BindingExpression.TryConvert(ref inputString, Entry.TextProperty, expected.GetType(), false);

Assert.AreEqual(expected, inputString);
Expand Down
2 changes: 1 addition & 1 deletion Xamarin.Forms.Core.UnitTests/BindingUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2000,7 +2000,7 @@ public void Convert()
#if !WINDOWS_PHONE
[TestCase("en-US", "0.5", 0.5, 0.9, "0.9")]
[TestCase("pt-PT", "0,5", 0.5, 0.9, "0,9")]
public void ConvertIsCultureInvariant(string culture, string sliderSetStringValue, double sliderExpectedDoubleValue, double sliderSetDoubleValue, string sliderExpectedStringValue)
public void ConvertIsCultureAware(string culture, string sliderSetStringValue, double sliderExpectedDoubleValue, double sliderSetDoubleValue, string sliderExpectedStringValue)
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);

Expand Down
2 changes: 1 addition & 1 deletion Xamarin.Forms.Core.UnitTests/TypedBindingUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ public void Convert()
#if !WINDOWS_PHONE
[TestCase("en-US", "0.5", 0.5, 0.9, "0.9")]
[TestCase("pt-PT", "0,5", 0.5, 0.9, "0,9")]
public void ConvertIsCultureInvariant(string culture, string sliderSetStringValue, double sliderExpectedDoubleValue, double sliderSetDoubleValue, string sliderExpectedStringValue)
public void ConvertIsCultureAware(string culture, string sliderSetStringValue, double sliderExpectedDoubleValue, double sliderSetDoubleValue, string sliderExpectedStringValue)
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);

Expand Down
4 changes: 2 additions & 2 deletions Xamarin.Forms.Core/BindingExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ internal static bool TryConvert(ref object value, BindableProperty targetPropert
var stringValue = value as string ?? string.Empty;
// see: https://bugzilla.xamarin.com/show_bug.cgi?id=32871
// do not canonicalize "*.[.]"; "1." should not update bound BindableProperty
if (stringValue.EndsWith(CultureInfo.CurrentUICulture.NumberFormat.NumberDecimalSeparator, StringComparison.Ordinal) && DecimalTypes.Contains(convertTo))
if (stringValue.EndsWith(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator, StringComparison.Ordinal) && DecimalTypes.Contains(convertTo))
{
value = original;
return false;
Expand All @@ -475,7 +475,7 @@ internal static bool TryConvert(ref object value, BindableProperty targetPropert
return false;
}

value = Convert.ChangeType(value, convertTo, CultureInfo.CurrentUICulture);
value = Convert.ChangeType(value, convertTo, CultureInfo.CurrentCulture);

return true;
}
Expand Down