summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues
diff options
context:
space:
mode:
authorSamantha Houts <samhouts@users.noreply.github.com>2017-08-17 08:59:13 -0700
committerSamantha Houts <samantha.houts@xamarin.com>2017-09-14 17:50:28 -0700
commitc2f6a9c16c06b50c2795a6e57a6ae77b2d7291d1 (patch)
treee3b01dcc0cfdf7e662e720ab588119e55e65d9d9 /Xamarin.Forms.Controls.Issues
parentb0a6d74e1e7746ab3605c91d1ae48b2b67325d18 (diff)
downloadxamarin-forms-c2f6a9c16c06b50c2795a6e57a6ae77b2d7291d1.tar.gz
xamarin-forms-c2f6a9c16c06b50c2795a6e57a6ae77b2d7291d1.tar.bz2
xamarin-forms-c2f6a9c16c06b50c2795a6e57a6ae77b2d7291d1.zip
[UWP] ListView ItemSelected event will fire only once on selection changed (#1005)
* Add repro for 44886 * [UWP] Fire ListItemClicked when Selection changes This will automatically set the value on the renderer and prevent the double event from firing. * Clean up repro * Update test case for delection scenario * [Core] Allow ListView item deselection * [UWP] Send events when item is deselected, too * Test works better when you DO something.
Diffstat (limited to 'Xamarin.Forms.Controls.Issues')
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla44886.cs90
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems1
2 files changed, 91 insertions, 0 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla44886.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla44886.cs
new file mode 100644
index 00000000..b9150cd2
--- /dev/null
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla44886.cs
@@ -0,0 +1,90 @@
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+using System.Collections.Generic;
+using System.Runtime.CompilerServices;
+using System.ComponentModel;
+
+#if UITEST
+using Xamarin.UITest;
+using NUnit.Framework;
+#endif
+
+namespace Xamarin.Forms.Controls.Issues
+{
+ [Preserve(AllMembers = true)]
+ [Issue(IssueTracker.Bugzilla, 44886, "UWP Listview ItemSelected event triggered twice for each selection", PlatformAffected.UWP)]
+ public class Bugzilla44886 : TestContentPage
+ {
+ const string Item1 = "Item 1";
+ const string Instructions = "Select one of the items in the list. The text in blue should show 1, indicating that the ItemSelected event fired once. If it shows 2, this test has failed. Be sure to also test Keyboard selection and Narrator selection. On UWP, the ItemSelected event should fire when an item is highlighted and again when it is un-highlighted (by pressing spacebar).";
+ const string CountId = "countId";
+
+ Label _CountLabel = new Label { AutomationId = CountId, TextColor = Color.Blue };
+ MyViewModel _vm = new MyViewModel();
+
+ [Preserve(AllMembers = true)]
+ class MyViewModel : INotifyPropertyChanged
+ {
+ int _count;
+ public int Count
+ {
+ get { return _count; }
+ set
+ {
+ if (value != _count)
+ {
+ _count = value;
+ RaisePropertyChanged();
+ }
+ }
+ }
+
+ void RaisePropertyChanged([CallerMemberName] string propertyName = null)
+ {
+ PropertyChangedEventHandler handler = PropertyChanged;
+
+ handler?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+ }
+
+ #region INotifyPropertyChanged implementation
+
+ public event PropertyChangedEventHandler PropertyChanged;
+
+ #endregion
+ }
+
+ protected override void Init()
+ {
+ BindingContext = _vm;
+
+ _CountLabel.SetBinding(Label.TextProperty, nameof(MyViewModel.Count));
+
+ var listView = new ListView
+ {
+ ItemsSource = new List<string> { Item1, "Item 2", "Item 3", "Item 4", "Item 5" }
+ };
+ listView.ItemSelected += ListView_ItemSelected;
+
+ var stack = new StackLayout { Children = { new Label { Text = Instructions }, _CountLabel, listView } };
+ Content = stack;
+ }
+
+ void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
+ {
+ _vm.Count++;
+ }
+
+#if UITEST
+ [Test]
+ public void Bugzilla44886Test()
+ {
+ RunningApp.WaitForElement(q => q.Marked(Item1));
+ RunningApp.Tap(q => q.Marked(Item1));
+
+ int count = int.Parse(RunningApp.Query(q => q.Marked(CountId))[0].Text);
+
+ Assert.IsTrue(count == 1);
+ }
+#endif
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
index 672c8dfd..1274dd27 100644
--- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
@@ -314,6 +314,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla54036.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla56896.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla40161.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla44886.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzila57749.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ScrollViewObjectDisposed.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla58645.cs" />