introduction to universal apps

55
Introduction to Universal Apps Jaliya Udagedara MVP (Visual C#)

Upload: jaliya-udagedara

Post on 14-Jul-2015

660 views

Category:

Software


1 download

TRANSCRIPT

Introduction to Universal Apps

Jaliya UdagedaraMVP (Visual C#)

Windows Store App

Windows Phone Store App

Windows Runtime Apps

Windows Runtime contains more than 90% of Windows

Phone Runtime

protected override async void OnLaunched(LaunchActivatedEventArgs e){

ApplicationExecutionState state = e.PreviousExecutionState;

ActivationKind kind = e.Kind;

///...}

• App is suspended

• All code stopped

• No timers tick

• No events fire

• Process still alive and in memory

• Code has a chance to respond (next slide)

private async void OnSuspending(object sender, SuspendingEventArgs e){

var deferral = e.SuspendingOperation.GetDeferral();

await SuspensionManager.SaveAsync(); deferral.Complete();

}

• Same app is resumed

• Same process, same memory so values of variables are intact

• All code runs

• Code has a chance to respond.

Launch Switcher

public App() {

this.InitializeComponent();this.Suspending += this.OnSuspending;this.Resuming += App_Resuming;

}

void App_Resuming(object sender, object e){

// TODO: whatever you need to do to resume your app}

http://bit.ly/w8Resuming

Window

Frame

PageWindow

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 activeif (rootFrame == null){

// Create a Frame to act as the navigation context and navigate// to the first pagerootFrame = new Frame();

...

// Place the frame in the current WindowWindow.Current.Content = rootFrame;

}

if (rootFrame.Content == null){

// Navigate to the first pagerootFrame.Navigate(typeof(MainPage), e.Arguments);

}// Ensure the current window is activeWindow.Current.Activate();

}

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);

}

private void btnGoBack_Click(object sender, RoutedEventArgs e)

{if (this.Frame.CanGoBack)

this.Frame.GoBack();}

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 (SecondaryUI.Visibility == Visibility.Visible ) // If the secondary UI is visible, hide it{

FadeOutSecondaryStoryboard.Begin();}else{

if (Frame.CanGoBack)Frame.GoBack();

}}

Add Windows Phone 8.1 or Windows 8.1

Context Switcher in the Editor

Context Switcher in the XAML Editor

Better IntelliSense

Devices Window

Switching Startup Projects

• Code Sharing Strategies

• Linked Files

• PCL

• Shared Projects

• XAML Sharing Strategies

• Solving Styles

Thank You!http://www.jaliyaudagedara.blogspot.com/