summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla21368.cs
blob: 1f6f14721b82122a732792830e34c213b4628412 (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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms.Controls.TestCasesPages
{
	[Preserve (AllMembers=true)]
	[Issue (IssueTracker.Bugzilla, 21368, "Button text alignment breaks if the buttons are in a stack layout inside another layout and the button is clicked", PlatformAffected.Android)]
	public class Bugzilla21368 : ContentPage
	{
		ScrollView _scrollView;
		StackLayout _buttonsStack;
		Grid _buttonsGrid;

		public Bugzilla21368 ()
		{
			_scrollView = new ScrollView {
				Orientation = ScrollOrientation.Horizontal,
				Content = new StackLayout {
					Orientation = StackOrientation.Horizontal
				},
				HeightRequest = 100
			};

			_buttonsGrid = new Grid {
				RowSpacing = 10
			};

			_buttonsGrid.Children.Add (_scrollView, 0, 0);
			_buttonsGrid.Children.Add (new Button {
				Text = "Add Control",
				Command = new Command (OnAddControl),
				WidthRequest=400
			}, 0, 1);
			_buttonsGrid.Children.Add (new Button {
				Text = "Insert Control",
				Command = new Command (OnInsertControl)
			}, 0, 2);
			_buttonsGrid.Children.Add (new Button {
				Text = "Remove Control",
				Command = new Command (OnRemoveControl)
			}, 0, 3);
			_buttonsStack = new StackLayout { Children = { _buttonsGrid } };

			Content = new StackLayout {
				Orientation = StackOrientation.Vertical,
				Children =
					{
						_buttonsStack
					}
			};
		}

		StackLayout ScrollStackLayout
		{
			get { return (StackLayout) _scrollView.Content; }
		}

		void OnAddControl ()
		{
			ScrollStackLayout.Children.Add (new Button { Text = "hello" });
			ForceRelayout ();
		}

		void OnInsertControl ()
		{
			ScrollStackLayout.Children.Insert (0, new Button {
				Text = "hello"
			});
			ForceRelayout ();
		}

		void OnRemoveControl ()
		{
			if (ScrollStackLayout.Children.Count > 0) {
				ScrollStackLayout.Children.RemoveAt (0);
				ForceRelayout ();
			}
		}

		void ForceRelayout ()
		{
			ScrollStackLayout.ForceLayout ();
			_scrollView.ForceLayout ();
		}
	}
}