-
Notifications
You must be signed in to change notification settings - Fork 0
/
NavigatorPage.xaml.cs
155 lines (135 loc) · 4.61 KB
/
NavigatorPage.xaml.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.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
namespace AmxMobile.Phone7.SixBookmarks
{
public partial class NavigatorPage : PhoneApplicationPage, IContextSource
{
private List<Bookmark> _bookmarks;
public NavigatorPage()
{
InitializeComponent();
}
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
// get a list of bookmarks and bind it...
this.Bookmarks = Bookmark.GetBookmarksForDisplay();
}
private List<Bookmark> Bookmarks
{
get
{
return _bookmarks;
}
set
{
_bookmarks = value;
this.RefreshView();
}
}
private void RefreshView()
{
// reset...
for (int index = 0; index < 5; index++)
ResetButton(index);
// configure...
foreach (Bookmark bookmark in this.Bookmarks)
ConfigureBookmark(bookmark);
}
private void ConfigureBookmark(Bookmark bookmark)
{
if (bookmark == null)
throw new ArgumentNullException("bookmark");
// get...
Button button = this.GetButton(bookmark.Ordinal);
if (button == null)
throw new InvalidOperationException("'button' is null.");
// set it...
button.Content = bookmark.Name;
}
private void ResetButton(int ordinal)
{
Button button = this.GetButton(ordinal);
button.Content = "...";
}
private Button GetButton(int ordinal)
{
if (ordinal == 0)
return this.buttonNavigate1;
else if (ordinal == 1)
return this.buttonNavigate2;
else if (ordinal == 2)
return this.buttonNavigate3;
else if (ordinal == 3)
return this.buttonNavigate4;
else if (ordinal == 4)
return this.buttonNavigate5;
else if (ordinal == 5)
return this.buttonNavigate6;
else
throw new NotSupportedException(string.Format("Cannot handle '{0}'.", ordinal));
}
private void buttonConfigure_Click(object sender, RoutedEventArgs e)
{
HandleConfigure();
}
private void buttonLogoff_Click(object sender, RoutedEventArgs e)
{
Alert.Show(this, "TBD.");
}
private void buttonAbout_Click(object sender, RoutedEventArgs e)
{
SixBookmarksRuntime.Current.ShowUrl("http://www.multimobiledevelopment.com/");
}
private void buttonNavigate_Click(object sender, RoutedEventArgs e)
{
int ordinal = GetOrdinalForButton((Button)sender);
// find it...
Bookmark bookmark = GetBookmarkForOrdinal(ordinal);
if (bookmark != null)
SixBookmarksRuntime.Current.ShowUrl(bookmark.Url);
else
HandleConfigure();
}
private int GetOrdinalForButton(Button button)
{
if (button == buttonNavigate1)
return 0;
else if (button == buttonNavigate2)
return 1;
else if (button == buttonNavigate3)
return 2;
else if (button == buttonNavigate4)
return 3;
else if (button == buttonNavigate5)
return 4;
else if (button == buttonNavigate6)
return 5;
else
throw new NotSupportedException(string.Format("Cannot handle '{0}'.", button.Name));
}
private Bookmark GetBookmarkForOrdinal(int ordinal)
{
foreach (Bookmark bookmark in this.Bookmarks)
{
if (bookmark.Ordinal == ordinal)
return bookmark;
}
// return...
return null;
}
private void HandleConfigure()
{
NavigationService.Navigate(new Uri("/ConfigurePage.xaml", UriKind.RelativeOrAbsolute));
}
}
}