This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix input for decimal/float/double and nullable (#11815)
* Fix input for decimal/float/double and nullable This commit fixes the input of decimal/float/double and their nullable equivalents in different cultures. Issue #7996 * Update UI test Makes the UI test more understandable. It shows now a label with the actual resolved binding value. In the entry you can now see the value you provided. * Fix unit test * Fix more unit tests Co-authored-by: Gerald Versluis <gerald@verslu.is> Co-authored-by: Gerald Versluis <gerald.versluis@microsoft.com>
- Loading branch information
1 parent
37589f0
commit a13a484
Showing
6 changed files
with
179 additions
and
17 deletions.
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Github7996.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using System.ComponentModel; | ||
using System.Globalization; | ||
using Xamarin.Forms.CustomAttributes; | ||
using Xamarin.Forms.Internals; | ||
|
||
#if UITEST | ||
using Xamarin.Forms.Core.UITests; | ||
using Xamarin.UITest; | ||
using NUnit.Framework; | ||
#endif | ||
|
||
namespace Xamarin.Forms.Controls.Issues | ||
{ | ||
|
||
[Preserve(AllMembers = true)] | ||
[Issue(IssueTracker.Github, 7996, "Xamarin.Forms.Entry does not enter decimal when binding a float/double and decimal to it", PlatformAffected.Default)] | ||
public class Issue7996 : TestContentPage | ||
{ | ||
protected override void Init() | ||
{ | ||
var vm = new ViewModelIssue7996(); | ||
BindingContext = vm; | ||
var textLabel1 = new Label | ||
{ | ||
Text = "Select culture:" | ||
}; | ||
var picker = new Picker(); | ||
picker.ItemsSource = new[] | ||
{ | ||
new CultureInfo("de"), | ||
new CultureInfo("en"), | ||
}; | ||
picker.SelectedIndexChanged += (s, e) => | ||
{ | ||
if (picker.SelectedItem is CultureInfo culture) | ||
{ | ||
CultureInfo.CurrentUICulture = culture; | ||
} | ||
}; | ||
|
||
var textLabel2 = new Label | ||
{ | ||
Text = "Resolved Binding Value:" | ||
}; | ||
var bindingLable = new Label(); | ||
bindingLable.SetBinding(Label.TextProperty, new Binding(nameof(ViewModelIssue7996.MyDecimal), BindingMode.TwoWay)); | ||
|
||
var textLabel3 = new Label | ||
{ | ||
Text = "Actual Value:" | ||
}; | ||
var bindingLable2 = new Label(); | ||
bindingLable2.SetBinding(Label.TextProperty, new Binding(nameof(ViewModelIssue7996.MyDecimal), BindingMode.TwoWay)); | ||
|
||
var textLabel4 = new Label | ||
{ | ||
Text = "Enter a number and watch result:" | ||
}; | ||
var entry = new Entry(); | ||
entry.Text = vm.MyDecimal.ToString(); | ||
entry.TextChanged += (s, e) => | ||
{ | ||
bindingLable.Text = e.NewTextValue; | ||
}; | ||
|
||
var stackLayout = new StackLayout | ||
{ | ||
Children = | ||
{ | ||
textLabel1, | ||
picker, | ||
textLabel2, | ||
bindingLable, | ||
textLabel3, | ||
bindingLable2, | ||
textLabel4, | ||
entry, | ||
} | ||
}; | ||
|
||
Content = stackLayout; | ||
} | ||
} | ||
|
||
[Preserve(AllMembers = true)] | ||
public class ViewModelIssue7996 : INotifyPropertyChanged | ||
{ | ||
|
||
decimal? myDecimal = 4.2m; | ||
|
||
public event PropertyChangedEventHandler PropertyChanged; | ||
|
||
public decimal? MyDecimal | ||
{ | ||
get | ||
{ | ||
return myDecimal; | ||
} | ||
set | ||
{ | ||
myDecimal = value; | ||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MyDecimal))); | ||
} | ||
} | ||
|
||
public ViewModelIssue7996() | ||
{ | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters