summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla31964.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla31964.cs')
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla31964.cs116
1 files changed, 116 insertions, 0 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla31964.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla31964.cs
new file mode 100644
index 00000000..da673f8f
--- /dev/null
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla31964.cs
@@ -0,0 +1,116 @@
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using Xamarin.Forms.CustomAttributes;
+
+namespace Xamarin.Forms.Controls
+{
+ [Preserve (AllMembers = true)]
+ [Issue (IssueTracker.Bugzilla, 31964, "[Xamarin.Forms SwitchCell]OnChange() did not work for Windows platform",
+ PlatformAffected.WinRT)]
+ public class Bugzilla31964 : TestContentPage
+ {
+ protected override void Init ()
+ {
+ var listView = new ListView ();
+
+ var selection = new Selection ();
+ listView.SetBinding (ListView.ItemsSourceProperty, "Items");
+
+ listView.ItemTemplate = new DataTemplate (() => {
+ var cell = new SwitchCell ();
+ cell.SetBinding (SwitchCell.TextProperty, "Name");
+ cell.SetBinding (SwitchCell.OnProperty, "IsSelected", BindingMode.TwoWay);
+ return cell;
+ });
+
+ var instructions = new Label {
+ FontSize = 16,
+ Text =
+ "The label at the bottom should equal the number of switches which are in the 'on' position. Flip some of the switches. If the number at the bottom does not equal the number of 'on' switches, the test has failed."
+ };
+
+ var label = new Label { FontSize = 24 };
+ label.SetBinding (Label.TextProperty, "SelectedCount");
+
+ Content = new StackLayout {
+ VerticalOptions = LayoutOptions.Fill,
+ Children = {
+ instructions,
+ listView,
+ label
+ }
+ };
+
+ BindingContext = selection;
+ }
+
+ [Preserve (AllMembers = true)]
+ public class SelectionItem : INotifyPropertyChanged
+ {
+ bool _isSelected;
+
+ public string Name { get; set; }
+
+ public bool IsSelected
+ {
+ get { return _isSelected; }
+ set
+ {
+ _isSelected = value;
+ OnPropertyChanged ();
+ }
+ }
+
+ public event PropertyChangedEventHandler PropertyChanged;
+
+ void OnPropertyChanged ([CallerMemberName] string propertyName = null)
+ {
+ PropertyChanged?.Invoke (this, new PropertyChangedEventArgs (propertyName));
+ }
+ }
+
+ [Preserve (AllMembers = true)]
+ public class Selection : INotifyPropertyChanged
+ {
+ int _selectedCount;
+
+ public Selection ()
+ {
+ Items = new List<SelectionItem> {
+ new SelectionItem { Name = "Item1" },
+ new SelectionItem { Name = "Item2" },
+ new SelectionItem { Name = "Item3", IsSelected = true },
+ new SelectionItem { Name = "Item4" },
+ new SelectionItem { Name = "Item5" }
+ };
+
+ SelectedCount = Items.Count (i => i.IsSelected);
+
+ foreach (SelectionItem selectionItem in Items) {
+ selectionItem.PropertyChanged += (sender, args) => SelectedCount = Items.Count (i => i.IsSelected);
+ }
+ }
+
+ public List<SelectionItem> Items { get; }
+
+ public int SelectedCount
+ {
+ get { return _selectedCount; }
+ set
+ {
+ _selectedCount = value;
+ OnPropertyChanged ();
+ }
+ }
+
+ public event PropertyChangedEventHandler PropertyChanged;
+
+ void OnPropertyChanged ([CallerMemberName] string propertyName = null)
+ {
+ PropertyChanged?.Invoke (this, new PropertyChangedEventArgs (propertyName));
+ }
+ }
+ }
+} \ No newline at end of file