summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue3276.cs
blob: d1a1558c76a785281b5f31581307e41e397d789f (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
using System;

using Xamarin.Forms.CustomAttributes;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.ComponentModel;
using Xamarin.Forms.Internals;

#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls.Issues
{
	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Github, 3276, "Crashing Unknown cell parent type on ContextAction Bindings")]
	public class Issue3276 : TestTabbedPage
	{
		protected override void Init ()
		{
			var listview = new ListView ();
			listview.ItemTemplate = new DataTemplate (typeof(CaCell));

			listview.SetBinding (ListView.ItemsSourceProperty, new Binding ("SearchResults"));

			var page = new ContentPage {Title = "First", Content = listview, BindingContext = new VM () };

			page.Appearing += (object sender, EventArgs e) => (page.BindingContext as VM).Load ();

			Children.Add (page);
			Children.Add (new ContentPage { Title = "Second" });
		}

		[Preserve (AllMembers = true)]
		public class VM : ViewModel
		{
			public void Load ()
			{
				var list = new List<string> ();
				for (int i = 0; i < 20; i++) {
					list.Add ("second " + i.ToString ());
				}
				SearchResults = new ObservableCollection<string> (list);
			}

			ObservableCollection<string> _list = null;

			public ObservableCollection<string> SearchResults {
				get { return _list; }

				set {
					_list = value;
					OnPropertyChanged ();
				}
			}

		}

		[Preserve (AllMembers = true)]
		public class CaCell : ViewCell
		{
			public CaCell ()
			{
				var label = new Label ();
				label.SetBinding (Label.TextProperty, new Binding ("."));
				var menu = new MenuItem { Text = "Delete", IsDestructive = true };
				menu.SetBinding (MenuItem.CommandParameterProperty, new Binding ("."));
				var menu1 = new MenuItem { Text = "Settings"  };
				menu1.SetBinding (MenuItem.CommandParameterProperty, new Binding ("."));
				ContextActions.Add (menu);
				ContextActions.Add (menu1);

				var stack = new StackLayout ();
				stack.Children.Add (label);
				View = stack;
			}
		}


		#if UITEST
		[Test]
		public void Issue3276Test ()
		{
			RunningApp.Tap (q => q.Marked ("Second"));
			RunningApp.Tap (q => q.Marked ("First"));
			RunningApp.WaitForElement (q => q.Marked ("second 1"));
		}
#endif
	}
}