This repository was archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathAppearingGalleryPage.cs
156 lines (141 loc) · 4.1 KB
/
AppearingGalleryPage.cs
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Xamarin.Forms;
namespace Xamarin.Forms.Controls
{
public class AppearingGalleryPage : ContentPage
{
const string NavPageTitle = "NavAppearingPage";
const string MasterPageTitle = "MasterAppearingPage";
const string TabbedPageTitle = "TabbedAppearingPage";
const string CarouselPageTitle = "CarouselAppearingPage";
public AppearingGalleryPage()
{
App.AppearingMessages.Clear();
var initalPage = new AppearingPage(1);
var initalPage2 = new AppearingPage(2);
Content = new StackLayout
{
Children = {
new Button { Text = NavPageTitle, Command = new Command (() => {
Application.Current.MainPage = new NavAppearingPage(initalPage);
})
},
new Button { Text = MasterPageTitle, Command = new Command (() => {
var page = new FlyoutPage {
Title = MasterPageTitle,
Flyout = new ContentPage { Title = "Flyout", BackgroundColor = Color.Red },
Detail = new NavAppearingPage(initalPage)
};
SetMainPage (page);
})
},
new Button { Text = TabbedPageTitle, Command = new Command (() => {
var page = new TabbedPage {
Title = TabbedPageTitle,
Children = { initalPage, initalPage2 }
};
SetMainPage (page);
})
},
new Button { Text = CarouselPageTitle, Command = new Command (() => {
var page = new CarouselPage {
Title = CarouselPageTitle,
Children = { initalPage, initalPage2 }
};
SetMainPage (page);
})
}
}
};
}
static void SetMainPage(Page page)
{
var tracker = new AppearingTracker(page);
Application.Current.MainPage = page;
}
class AppearingTracker
{
int _isAppearingFired;
int _isDisappearingFired;
public AppearingTracker(Page page)
{
page.Appearing += (object sender, EventArgs e) =>
{
_isAppearingFired++;
App.AppearingMessages.Insert(0, $"Appearing {page.Title}");
Debug.WriteLine($"Appearing {page.Title}");
};
page.Disappearing += (object sender, EventArgs e) =>
{
_isDisappearingFired++;
App.AppearingMessages.Insert(0, $"Disappearing {page.Title}");
Debug.WriteLine($"Disappearing {page.Title}");
};
}
}
class AppearingPage : ContentPage
{
static int added_carouselpage_id = 3;
static int added_tabpage_id = 3;
int _theId;
ListView _listMessages;
public AppearingPage(int id)
{
var tracker = new AppearingTracker(this);
_listMessages = new ListView();
_theId = id;
Title = $"Page {_theId}";
Padding = new Thickness(20);
Content = new StackLayout
{
Children = {
new Label { Text = $"Hello Appearing {_theId} page" },
new Button { Text = "Push new Page", Command = new Command ( async () => { await Navigation.PushAsync( new AppearingPage(2)); }) },
new Button { Text = "Add new Page",
Command = new Command ( () =>
{
switch (Parent)
{
case CarouselPage cp:
cp.Children.Add( new AppearingPage(added_carouselpage_id++));
break;
case TabbedPage tp:
tp.Children.Add( new AppearingPage(added_tabpage_id++));
break;
default:
break;
}
})
},
new Button { Text = "Pop page", Command = new Command ( async () => { await Navigation.PopAsync(); }) },
new Button { Text = "Pop to root", Command = new Command ( async () => { await Navigation.PopToRootAsync(); }) },
new Button { Text = "Change Main Page", Command = new Command ( () => {
App.AppearingMessages.Clear();
Application.Current.MainPage = new AppearingPage(3); })
},
_listMessages
}
};
}
protected override void OnAppearing()
{
base.OnAppearing();
Device.StartTimer(TimeSpan.FromMilliseconds(750), () =>
{
_listMessages.ItemsSource = App.AppearingMessages;
return false;
});
}
}
class NavAppearingPage : NavigationPage
{
public NavAppearingPage(Page page) : base(page)
{
Title = NavPageTitle;
var tracker = new AppearingTracker(this);
}
}
}
}