This document provides an overview of key concepts for building apps for Windows Phone 8.1, including navigation, view models, data binding, and more. It discusses using frames to navigate between pages, passing parameters between pages, handling the back button, and caching pages. It also covers implementing INotifyPropertyChanged for view models, binding to view models, and using fallback values and modes in bindings.
5. protected override void OnLaunched(LaunchActivatedEventArgs e)
{
Frame rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has
// content, just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate
// to the first page
rootFrame = new Frame();
...
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
if (rootFrame.Content == null)
{
// Navigate to the first page
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
// Ensure the current window is active
Window.Current.Activate();
}
6. private void itemListView_ItemClick(object sender, ItemClickEventArgs e)
{
// Navigate to the appropriate destination page, configuring the new page
// by passing required information as a navigation parameter
var itemId = ((MyListViewItem)e.ClickedItem).UniqueId;
Frame.Navigate(typeof(MyDetailPage), itemId);
}
You are responsible for context
When navigating to a page, you are responsible for providing any parameters/data using the
“parameter” parameter of the Navigate method.
8. In Windows Phone Store apps, you must include code to
override this to cause a backwards navigation within the app
Differs from Windows Phone Silverlight – within an app,
backwards page navigation is default for that framework
Differs from Windows Phone Silverlight – Closes the current
app in that framework
9.
10. public sealed partial class SecondPage : Page
{
...
protected override void OnNavigatedTo(NavigationEventArgs e)
{
Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
Windows.Phone.UI.Input.HardwareButtons.BackPressed -= HardwareButtons_BackPressed;
}
async void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
{
e.Handled = true; // We've handled this button press
// If the secondary UI is visible, hide it
if (SecondaryUI.Visibility == Visibility.Visible )
{
FadeOutSecondaryStoryboard.Begin();
}
else
{
// Standard page backward navigation
if (Frame.CanGoBack)
Frame.GoBack();
}
}