Session 4.5 - Marek Piasecki

marek.piasecki.staff.iiar.pwr.wroc.pl

Session 4.5 - Marek Piasecki

Session 4.5


Topics

Topics

Windows Phone


3

The The Story Story So So Far

Far

Windows Phone


4

Multi Multi-page Multi Multi page applications

Windows Phone


5

Adding Adding another another another page

page

Windows Phone


6

Pages Pages and and projects

projects

Windows Phone


7

Page Page Navigation

Navigation

private void page2Button_Click(object sender,

RoutedEventArgs e)

{

NavigationService.Navigate(

new Uri("/CustomerDetailPage.xaml",

UriKind.RelativeOrAbsolute));

}

Windows Phone


8

The The UriKind UriKind

UriKind

private void page2Button_Click(object sender,

RoutedEventArgs e)

{

NavigationService.Navigate(

new Uri("/CustomerDetailPage.xaml",

UriKind.RelativeOrAbsolute));

}

Windows Phone


9

Missing Missing Missing page page exceptions

exceptions

Windows Phone


10

Using Using the the the Back Back button button

button

Windows Phone


11

Overriding Overriding the the Back Back button

button

Windows Phone


12

Disabling Disabling the the Back Back Back Button

Button

private void PhoneApplicationPage_BackKeyPress(

object sender,

System.ComponentModel.CancelEventArgs

e)

{

e.Cancel = true;

}

Windows Phone


Using Using a a a MessageBox

MessageBox

private void PhoneApplicationPage_BackKeyPress(

object sender,

System.ComponentModel.CancelEventArgs e)

{

if (MessageBox.Show("Do you really want to exit?",

"Page Exit",

MessageBoxButton.OKCancel)

!= MessageBoxResult.OK)

{

e.Cancel = true;

}

}

13

Windows Phone


14

Passing Passing data data data between between pages

pages

Windows Phone


15

Assembling Assembling a a data data data uri

uri

// Get the selected customer from the list

Customer selectedCustomer = customerList.SelectedItem

as Customer;

// Build a navigation string containing the information

NavigationService.Navigate(

new Uri("/CustomerDetailPage.xaml?" +

"name=" + selectedCustomer.Name + "&" +

"address=" + selectedCustomer.Address,

UriKind.Relative));

Windows Phone


16

Page Page navigated navigated events

events

Windows Phone


Loading Loading data data from from the the the uri

uri

protected override void OnNavigatedTo

(System.Windows.Navigation.NavigationEventArgs e)

{

string name, address;

if (NavigationContext.QueryString.TryGetValue("name",

out name))

nameTextBlock.Text = name;

}

17

Windows Phone


Demo 2: Passing Data

18

Windows Phone


19

Sharing Sharing objects objects between between pages

pages

Windows Phone


20

The The App.xaml App.xaml page

page

Windows Phone


The The App App class

class

public partial class App : Application

{

// To be used from all pages in the application

public Customer ActiveCustomer;

}

21

Windows Phone


Getting Getting a a reference reference reference to to to the the App App

App

protected override void OnNavigatedTo(

System.Windows.Navigation.NavigationEventArgs e)

{

base.OnNavigatedTo(e);

22

// Get the parent App containing the active customer

App thisApp = Application.Current as App;

// Set the data context for the Grid to the selected

// customer

customerDisplayGrid.DataContext = thisApp.ActiveCustomer;

}

Windows Phone


Getting Getting a a reference reference reference to to to the the App App

App

protected override void OnNavigatedTo(

System.Windows.Navigation.NavigationEventArgs e)

{

base.OnNavigatedTo(e);

23

// Get the parent App containing the active customer

App thisApp = Application.Current as App;

// Set the data context for the Grid to the selected

// customer

customerDisplayGrid.DataContext = thisApp.ActiveCustomer;

}

Windows Phone


Getting Getting a a reference reference reference to to to the the App App

App

protected override void OnNavigatedTo(

System.Windows.Navigation.NavigationEventArgs e)

{

base.OnNavigatedTo(e);

24

// Get the parent App containing the active customer

App thisApp = Application.Current as App;

// Set the data context for the Grid to the selected

// customer

customerDisplayGrid.DataContext = thisApp.ActiveCustomer;

}

Windows Phone


Getting Getting a a reference reference reference to to to the the App App

App

protected override void OnNavigatedTo(

System.Windows.Navigation.NavigationEventArgs e)

{

base.OnNavigatedTo(e);

25

// Get the parent App containing the active customer

App thisApp = Application.Current as App;

// Set the data context for the Grid to the selected

// customer

customerDisplayGrid.DataContext = thisApp.ActiveCustomer;

}

Windows Phone


Setting Setting Setting the the Edit Edit Edit Data Data Context

Context

protected override void OnNavigatedTo(

System.Windows.Navigation.NavigationEventArgs e)

{

base.OnNavigatedTo(e);

26

// Get the parent App containing the active customer

App thisApp = Application.Current as App;

// Set the data context for the Grid to the selected

// customer

customerDisplayGrid.DataContext = thisApp.ActiveCustomer;

}

Windows Phone


Demo 3: Shared Data

27

Windows Phone


28

Review Review

Review

Windows Phone

More magazines by this user
Similar magazines