-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSplitPage.xaml.cs
executable file
·240 lines (214 loc) · 11.4 KB
/
SplitPage.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
using Horoscope.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.System;
using Windows.UI.ApplicationSettings;
using Windows.UI.Popups;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Split Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234234
namespace Horoscope
{
/// <summary>
/// A page that displays a group title, a list of items within the group, and details for
/// the currently selected item.
/// </summary>
public sealed partial class SplitPage : Horoscope.Common.LayoutAwarePage
{
public SplitPage()
{
this.InitializeComponent();
this.SizeChanged += (a, b) =>
{
ApplicationViewState views = ApplicationView.Value;
VisualStateManager.GoToState(this, views.ToString(), false);
};
SettingsPane.GetForCurrentView().CommandsRequested += Horoscope_CommandsRequested;
}
void Horoscope_CommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
{
args.Request.ApplicationCommands.Clear();
SettingsCommand privacy = new SettingsCommand("priv", "Privacy Policy", (uicommand) => { ShowPrivacyPanel(); });
args.Request.ApplicationCommands.Add(privacy);
}
private async void ShowPrivacyPanel()
{
Uri uri = new Uri("https://skydrive.live.com/redir?resid=8DA942FCA8B8BEDD!120&authkey=!APh3pnqu9mDxxI8&ithint=file%2c.docx");
await Launcher.LaunchUriAsync(uri);
}
#region Page state management
/// <summary>
/// Populates the page with content passed during navigation. Any saved state is also
/// provided when recreating a page from a prior session.
/// </summary>
/// <param name="navigationParameter">The parameter value passed to
/// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
/// </param>
/// <param name="pageState">A dictionary of state preserved by this page during an earlier
/// session. This will be null the first time a page is visited.</param>
protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{
// TODO: Assign a bindable group to this.DefaultViewModel["Group"]
// TODO: Assign a collection of bindable items to this.DefaultViewModel["Items"]
DateTime thisDate = DateTime.Now;
string feedTitle = "Astrology and Horoscope "+thisDate.Year+" by www.findyourfate.com";
FeedData feedData = FeedDataSource.GetFeed(feedTitle);
if (feedData != null)
{
this.DefaultViewModel["Feeds"] = feedData;
this.DefaultViewModel["Items"] = feedData.Items;
}
else
{
itemListView.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
itemDetail.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
titlePanel.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
nointernet.Visibility = Windows.UI.Xaml.Visibility.Visible;
no.Visibility = Windows.UI.Xaml.Visibility.Visible;
}
if (pageState == null)
{
// When this is a new page, select the first item automatically unless logical page
// navigation is being used (see the logical page navigation #region below.)
if (!this.UsingLogicalPageNavigation() && this.itemsViewSource.View != null)
{
this.itemsViewSource.View.MoveCurrentToFirst();
}
}
else
{
// Restore the previously saved state associated with this page
if (pageState.ContainsKey("SelectedItem") && this.itemsViewSource.View != null)
{
// TODO: Invoke this.itemsViewSource.View.MoveCurrentTo() with the selected
// item as specified by the value of pageState["SelectedItem"]
string itemTitle = (string)pageState["SelectedItem"];
FeedItem selectedItem = FeedDataSource.GetItem(itemTitle);
this.itemsViewSource.View.MoveCurrentTo(selectedItem);
}
}
}
/// <summary>
/// Preserves state associated with this page in case the application is suspended or the
/// page is discarded from the navigation cache. Values must conform to the serialization
/// requirements of <see cref="SuspensionManager.SessionState"/>.
/// </summary>
/// <param name="pageState">An empty dictionary to be populated with serializable state.</param>
protected override void SaveState(Dictionary<String, Object> pageState)
{
if (this.itemsViewSource.View != null)
{
var selectedItem = this.itemsViewSource.View.CurrentItem;
// TODO: Derive a serializable navigation parameter and assign it to
// pageState["SelectedItem"]
if (selectedItem != null)
{
string itemTitle = ((FeedItem)selectedItem).Title;
pageState["SelectedItem"] = itemTitle;
}
}
}
#endregion
#region Logical page navigation
// Visual state management typically reflects the four application view states directly
// (full screen landscape and portrait plus snapped and filled views.) The split page is
// designed so that the snapped and portrait view states each have two distinct sub-states:
// either the item list or the details are displayed, but not both at the same time.
//
// This is all implemented with a single physical page that can represent two logical
// pages. The code below achieves this goal without making the user aware of the
// distinction.
/// <summary>
/// Invoked to determine whether the page should act as one logical page or two.
/// </summary>
/// <param name="viewState">The view state for which the question is being posed, or null
/// for the current view state. This parameter is optional with null as the default
/// value.</param>
/// <returns>True when the view state in question is portrait or snapped, false
/// otherwise.</returns>
private bool UsingLogicalPageNavigation(ApplicationViewState? viewState = null)
{
if (viewState == null) viewState = ApplicationView.Value;
return viewState == ApplicationViewState.FullScreenPortrait ||
viewState == ApplicationViewState.Snapped;
}
/// <summary>
/// Invoked when an item within the list is selected.
/// </summary>
/// <param name="sender">The GridView (or ListView when the application is Snapped)
/// displaying the selected item.</param>
/// <param name="e">Event data that describes how the selection was changed.</param>
void ItemListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// Invalidate the view state when logical page navigation is in effect, as a change
// in selection may cause a corresponding change in the current logical page. When
// an item is selected this has the effect of changing from displaying the item list
// to showing the selected item's details. When the selection is cleared this has the
// opposite effect.
if (this.UsingLogicalPageNavigation()) this.InvalidateVisualState();
}
/// <summary>
/// Invoked when the page's back button is pressed.
/// </summary>
/// <param name="sender">The back button instance.</param>
/// <param name="e">Event data that describes how the back button was clicked.</param>
protected override void GoBack(object sender, RoutedEventArgs e)
{
if (this.UsingLogicalPageNavigation() && itemListView.SelectedItem != null)
{
// When logical page navigation is in effect and there's a selected item that
// item's details are currently displayed. Clearing the selection will return to
// the item list. From the user's point of view this is a logical backward
// navigation.
this.itemListView.SelectedItem = null;
}
else
{
// When logical page navigation is not in effect, or when there is no selected
// item, use the default back button behavior.
base.GoBack(sender, e);
}
}
/// <summary>
/// Invoked to determine the name of the visual state that corresponds to an application
/// view state.
/// </summary>
/// <param name="viewState">The view state for which the question is being posed.</param>
/// <returns>The name of the desired visual state. This is the same as the name of the
/// view state except when there is a selected item in portrait and snapped views where
/// this additional logical page is represented by adding a suffix of _Detail.</returns>
protected override string DetermineVisualState(ApplicationViewState viewState)
{
// Update the back button's enabled state when the view state changes
var logicalPageBack = this.UsingLogicalPageNavigation(viewState) && this.itemListView.SelectedItem != null;
var physicalPageBack = this.Frame != null && this.Frame.CanGoBack;
this.DefaultViewModel["CanGoBack"] = logicalPageBack || physicalPageBack;
// Determine visual states for landscape layouts based not on the view state, but
// on the width of the window. This page has one layout that is appropriate for
// 1366 virtual pixels or wider, and another for narrower displays or when a snapped
// application reduces the horizontal space available to less than 1366.
if (viewState == ApplicationViewState.Filled ||
viewState == ApplicationViewState.FullScreenLandscape)
{
var windowWidth = Window.Current.Bounds.Width;
if (windowWidth >= 1366) return "FullScreenLandscapeOrWide";
return "FilledOrNarrow";
}
// When in portrait or snapped start with the default visual state name, then add a
// suffix when viewing details instead of the list
var defaultStateName = base.DetermineVisualState(viewState);
return logicalPageBack ? defaultStateName + "_Detail" : defaultStateName;
}
#endregion
}
}