summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla22401.cs
blob: af34e02a4f12cd11f56a9547453759ca30a24dc4 (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
105
106
107
108
109
110
111
112
113
114
115
using System.Collections.Generic;
using System.Linq;
using Xamarin.Forms.Controls.Issues;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms.Controls.TestCasesPages
{
	[Preserve (AllMembers=true)]
	[Issue (IssueTracker.Bugzilla, 22401, "MasterDetailPage detail width broken when landscape", PlatformAffected.iOS, NavigationBehavior.PushAsync)]
	public class Bugzilla22401 : MasterDetailPage
	{
		public Bugzilla22401()
		{
			List<Person> people = GetDemoData ();

			// Create the ListView.
			var listView = new ListView {
				// Source of data items.
				ItemsSource = people,

				// Define template for displaying each item.
				// (Argument of DataTemplate constructor is called for 
				//      each item; it must return a Cell derivative.)
				ItemTemplate = new DataTemplate (() => {
					// Create views with bindings for displaying each property.
					Label nameLabel = new Label();
					nameLabel.SetBinding (Label.TextProperty, "Name");

					// Return an assembled ViewCell.
					return new ViewCell {
						View = new StackLayout {
							Padding = new Thickness(0, 5),
							Orientation = StackOrientation.Horizontal,
							Children = {
								new StackLayout {
									VerticalOptions = LayoutOptions.Center,
									Spacing = 0,
									Children = {
										nameLabel
									}
								}
							}
						}
					};
				})
			};

			Master = new ContentPage { Title = "master", Icon = "menuIcon.png", Content = listView };

			listView.ItemSelected += (sender, e) => {
				Detail = CreateDetailPage (string.Format("Page {0}", (e.SelectedItem as Person).Name));
				IsPresented = false;
			};
			listView.SelectedItem = people.First ();
		}

		static List<Person> GetDemoData()
		{
			List<Person> people = new List<Person> {
				new Person("Abigail"),
				new Person("Bob"),
				new Person("Cathy"), 
				new Person("David"),
				new Person("Eugenie"),
				new Person("Freddie"),
				new Person("Greta"), 
				new Person("Harold"),
				new Person("Irene"),
				new Person("Jonathan"),
				new Person("Kathy"),
				new Person("Larry"),
				new Person("Monica"),
				new Person("Nick"),
				new Person("Olive"),
				new Person("Pendletonlow"),
				new Person("Queenie"),
				new Person("Rob"),
				new Person("Sally"),
				new Person("Timothy"),
				new Person("Uma"),
				new Person("Victor"),
				new Person("Wendy"),
				new Person("Xavier"),
				new Person("Yvonne"),
				new Person("Zachary"),
			};
			return people;
		}

		static Page CreateDetailPage(string text)
		{
			var page = new ContentPage {
				Title = text,
				Content = new StackLayout {
					Children = {
						new Label { 
							Text = text,
							VerticalOptions = LayoutOptions.CenterAndExpand,
							HorizontalOptions = LayoutOptions.CenterAndExpand,
						}
					}
				}
			};

			var tbiBank = new ToolbarItem { Command = new Command (() => { }), Icon = "bank.png" };
			var tbiCalc = new ToolbarItem { Command = new Command (() => { }), Icon = "calculator.png" };

			page.ToolbarItems.Add (tbiBank);
			page.ToolbarItems.Add (tbiCalc);

			return new NavigationPage (page);
		}
	}
}