summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue1763.cs
blob: e6cb31f399edea676268e76041393c4036e7ecec (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms.CustomAttributes;

namespace Xamarin.Forms.Controls
{
	[Preserve (AllMembers=true)]
	[Issue (IssueTracker.Github, 1763, "First item of grouped ListView not firing .ItemTapped", PlatformAffected.WinPhone, NavigationBehavior.PushAsync)]
	public class Issue1763 : TabbedPage
	{
		public Issue1763 ()
		{
			Title = "Contacts";

			Children.Add (new ContactsPage ());
		}
	}

	public class ContactsPage : ContentPage
	{
		public ContactsPage ()
		{
			var listView = new ListView {
				ItemTemplate = new DataTemplate (() => {
					var cell = new TextCell ();
					cell.SetBinding (TextCell.TextProperty, new Binding ("Name"));
					cell.SetBinding (TextCell.DetailProperty, new Binding ("Number"));
					return cell;
				}),
				IsGroupingEnabled = true,
				GroupDisplayBinding = new Binding ("Name")
			};

			var groupedContacts = new ObservableCollection<Group<ContactViewModel>> {
				new Group<ContactViewModel> ("E", new[] {
					new ContactViewModel { Name = "Egor1", Number = "'Tap' on this item won't fire the event" },
					new ContactViewModel { Name = "Egor2", Number = "123" },
					new ContactViewModel { Name = "Egor3", Number = "123" },
				})
			};

			listView.ItemsSource = groupedContacts;
			listView.ItemTapped += ListViewOnItemTapped;

			Content = listView;
		}

		void ListViewOnItemTapped (object sender, ItemTappedEventArgs itemTappedEventArgs)
		{
			DisplayActionSheet ("Tapped a List item", "Cancel", "Destruction");
		}
	}

	public class ContactViewModel : ViewModelBase2
	{
		string _name;
		string _number;

		public string Name
		{
			get { return _name; }
			set { SetProperty (ref _name, value); }
		}

		public string Number
		{
			get { return _number; }
			set { SetProperty (ref _number, value); }
		}
	}

	public class Group<TItem> : ObservableCollection<TItem>
	{
		public Group (string name, IEnumerable<TItem> items)
		{
			Name = name;
			foreach (var item in items)
				Add (item);
		}

		public string Name { get; set; }
	}

	public class ViewModelBase2 : INotifyPropertyChanged
	{
		public event PropertyChangedEventHandler PropertyChanged;

		protected virtual ViewModelBase2 SetProperty<T> (ref T field, T value, [CallerMemberName] string propertyName = null)
		{
			field = value;
			PropertyChangedEventHandler handler = PropertyChanged;
			if (handler != null)
				handler (this, new PropertyChangedEventArgs (propertyName));
			return this;
		}
	}
}