summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla33870.cs
blob: 888ddefe5172c5a326cf8859c35a0b62671f40d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms.Controls
{

	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Bugzilla, 33870, "[W] Crash when the ListView Selection is set to null", PlatformAffected.WinRT)]
	public class Bugzilla33870 : TestContentPage
	{
		public class Section : ObservableCollection<string>
		{
			public Section (string title, IEnumerable<string> items = null)
				: this (items ?? new List<string> ())
			{
				Title = title;
			}

			public Section (IEnumerable<string> items)
				: base (items)
			{ }

			public string Title { get; set; }
		}

		protected override void Init ()
		{
			var source = new ObservableCollection<Section> {
				new Section("SECTION 1") {
					"ITEM 1",
					"ITEM 2",
				},
				new Section("SECTION 2") {
					"ITEM 3",
					"CLEAR SELECTION",
				}
			};

			var listview = new ListView {
				ItemsSource = source,
				IsGroupingEnabled = true,
				GroupDisplayBinding = Binding.Create<Section> (x => x.Title),
			};

			var label = new Label { Text = "Tap CLEAR SELECTION. If the app does not crash and no item is selected, the test has passed." };

			listview.ItemSelected += (sender, args) =>
			{
				string selecteditem = args.SelectedItem?.ToString ();
				label.Text = selecteditem;
				if (selecteditem == "CLEAR SELECTION") {
					label.Text = "cleared";
					((ListView) sender).SelectedItem = null;
				}
			};

			var stack = new StackLayout {
				Children = {
					label,
					listview
				}
			};

			Content = stack;
		}
	}
}