SlideShare ist ein Scribd-Unternehmen logo
1 von 34
Windows	
  Phone:	
  	
  
Naviga1on	
  between	
  Pages	
  
            Jussi	
  Pohjolainen	
  
Tampere	
  University	
  of	
  Applied	
  Sciences	
  
Programming	
  Environments	
  
•  Two	
  programming	
  environments	
  
    –  XNA	
  –	
  for	
  games	
  
    –  Silverlight	
  –	
  non-­‐games	
  
•  You	
  can	
  mix	
  some	
  of	
  the	
  libraries	
  
•  When	
  crea1ng	
  a	
  project,	
  you	
  must	
  decide	
  if	
  
   you	
  are	
  doing	
  a	
  XNA	
  or	
  Silverlight	
  
Silverlight:	
  for	
  apps	
  and	
  u1li1es	
  
•  Silverlight	
  apps	
  are	
  combina1on	
  of	
  code	
  and	
  
   markup	
  
•  Extensible	
  markup	
  language	
  (XAML),	
  
   pronounced	
  “zammel”	
  
XNA:	
  for	
  games	
  
•  High	
  performance	
  games:	
  2D	
  and	
  3D	
  
•  Sprites	
  and	
  backgrounds	
  based	
  on	
  bitmaps	
  
•  Moving	
  objects	
  around	
  screen,	
  polling	
  user	
  
     input,	
  built-­‐in	
  XNA	
  loop	
  
	
  
Silverlight	
  files	
  
•  Markup	
  files	
  and	
  “code	
  behind”	
  files:	
  
   –  App.xaml	
  
   –  App.xaml.cs	
  
   –  MainPage.xaml	
  
   –  MainPage.xaml.cs	
  
App.xaml.cs:	
  	
  
       App	
  wide	
  init,	
  startup	
  and	
  shutdown	
  
namespace PhoneApp8
{

    public partial class App : Application
    {                                              Par1al	
  class!	
  So	
  
        public App()                                another	
  App-­‐
                                                    class	
  must	
  be	
  
        {                                           somewhere!	
  
            ...
            InitializeComponent();
            ...
App.xaml	
  
•  App.xaml	
  and	
  App.xaml.cs	
  files	
  together	
  are	
  
   the	
  App-­‐class	
  
•  How	
  can	
  .xaml	
  file	
  be	
  part	
  of	
  .cs?	
  
   –  During	
  compila1on	
  
       •  App.xaml	
  -­‐>	
  App.g.cs	
  !	
  
       •  g	
  stands	
  for	
  generated	
  
App.g.cs	
  
namespace PhoneApp8 {

    public partial class App : System.Windows.Application {

        private bool _contentLoaded;

        [System.Diagnostics.DebuggerNonUserCodeAttribute()]
        public void InitializeComponent() {
            if (_contentLoaded) {
                return;
            }
            _contentLoaded = true;
            System.Windows.Application.LoadComponent(this, new System.Uri("/
PhoneApp8;component/App.xaml", System.UriKind.Relative));
        }
    }
}
App.xaml	
  

<Application
    x:Class="PhoneApp8.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone">

    <!--Application Resources-->
    <Application.Resources>
                                                                      Store	
  
    </Application.Resources>
                                                                    resources:	
  
                                                                  colors,	
  styles..	
  	
  	
  
    <Application.ApplicationLifetimeObjects>
        <!--Required object that handles lifetime events for the application-->
        <shell:PhoneApplicationService
            Launching="Application_Launching" Closing="Application_Closing"
            Activated="Application_Activated" Deactivated="Application_Deactivated"/>
    </Application.ApplicationLifetimeObjects>

</Application>
MainPage.xaml.cs	
  
•  When	
  app	
  is	
  ini1alized	
  the	
  App	
  class	
  opens	
  the	
  Main	
  Page	
  
•  Again	
  par1al	
  class!	
  The	
  other	
  half	
  is	
  in	
  MainPage.xaml.cs	
  
	
  
namespace PhoneApp8
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }
}
MainPage.cs	
  
•  Contains	
  visual	
  elements	
  of	
  the	
  main	
  page	
  
PhoneApplicationFrame
  PhoneApplicationPage
    Grid named “LayoutRoot”
      StackPanel named “TitlePanel”
        TextBlock named “ApplicationTitle”
        TextBlock named “PageTitle”
      Grid named “ContentPanel”
Xap	
  is	
  Zip	
  
•  binDebug	
  dir	
  has	
  .xap	
  file	
  
    –  Pronounced	
  “zap”	
  
•  This	
  is	
  the	
  file	
  to	
  be	
  deployed	
  to	
  phone	
  or	
  
   emulator	
  
NAVIGATION	
  AND	
  LIFECYCLE	
  
Basic	
  Structure	
  
•  App	
  class	
  starts	
  the	
  app	
  
•  PhoneApplicationFrame	
  instance	
  can	
  host	
  
   one	
  or	
  more	
  pages	
  
•  PhoneApplicationPage	
  instances	
  are	
  the	
  
   pages	
  
MainPage	
  
namespace PhoneApp8
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }
      …
}
Navigate	
  
•  Naviga1on	
  is	
  based	
  on	
  XAML-­‐files	
  (like	
  .html	
  
   files	
  in	
  Web)	
  
•  Use	
  Naviga1on	
  Service	
  to	
  navigate	
  
    –  Naviga1onService.Navigate(new	
  Uri("/
       SecondPage.xaml",	
  UriKind.Rela1ve));	
  
    –  Naviga1onService.GoBack();	
  
public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        private void navigateButton_Click(object sender,
RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/SecondPage.xaml",
UriKind.Relative));
        }
    }
About	
  Naviga1on	
  
•  Last-­‐in-­‐first-­‐out	
  =>	
  Stack	
  
•  Phones	
  back	
  bueon	
  is	
  the	
  same	
  than	
  
    –  Naviga1onService.GoBack();	
  
•  To	
  create	
  new	
  instance	
  of	
  the	
  page:	
  
    –  Naviga1onService.Navigate(new	
  Uri("/
       MainPage.xaml",	
  UriKind.Rela1ve));	
  
RETAIN	
  DATA	
  ACROSS	
  PAGES	
  
Possibili1es	
  
•  Every	
  1me	
  you	
  navigate	
  to	
  new	
  page,	
  a	
  new	
  
   instance	
  is	
  created	
  =>	
  data	
  loss	
  
•  Solu1ons	
  
    –  1)	
  Just	
  pass	
  data	
  across	
  pages	
  
    –  2)	
  PhoneApplica1onService:	
  data	
  in	
  memory	
  while	
  
       app	
  running	
  
    –  3)	
  IsolatedStorage:	
  persistant	
  storage	
  	
  
Page	
  1	
  to	
  Page	
  2	
  
•  Pass	
  values	
  like	
  in	
  Web!	
  
    –  	
  NavigationService.Navigate(new Uri("/
       SecondPage.xaml?name=Jussi",
       UriKind.Relative));
To	
  receive	
  the	
  parameters	
  
 protected override void
OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            IDictionary<string, string> parameters =
NavigationContext.QueryString;
            if (parameters.ContainsKey("name"))
            {
                PageTitle.Text = parameters["name"];
            }
            base.OnNavigatedTo(e);
        }
Give	
  values	
  back	
  
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
       {
           if (e.Content is MainPage)
           {
               MainPage reference = (e.Content as MainPage);
               reference.PageTitle.Text = "And we are back!";
           }
           base.OnNavigatedFrom(e);
       }
Basics	
  
•  When	
  app	
  is	
  opened	
  from	
  Start	
  screen	
  
    –  App	
  is	
  launched	
  
•  When	
  app	
  is	
  terminated	
  as	
  result	
  of	
  Back	
  
    –  App	
  is	
  closed	
  
•  When	
  program	
  is	
  running	
  and	
  user	
  presses	
  
   start	
  
    –  App	
  is	
  deac1vated	
  -­‐>	
  tombstoned	
  state	
  
•  When	
  program	
  is	
  navigated	
  back	
  
    –  App	
  is	
  ac1vated	
  -­‐>	
  back	
  from	
  tombstoned	
  state	
  
public partial class App : Application
   {
       ...
       private void Application_Launching(object sender, LaunchingEventArgs e)
       {
           Debug.WriteLine("* Launch! *");
       }

       private void Application_Activated(object sender, ActivatedEventArgs e)
       {
           Debug.WriteLine("* Activate! *");
       }

       private void Application_Deactivated(object sender, DeactivatedEventArgs e)
       {
           Debug.WriteLine("* Deactivate! *");
       }

       private void Application_Closing(object sender, ClosingEventArgs e)
       {
           Debug.WriteLine("* Closed! *");
       }
PhoneApplica1onService:	
  
      Store	
  Data	
  while	
  App	
  in	
  Memory	
  
•  You	
  can	
  use	
  PhoneApplica1onService	
  to	
  store	
  
   data	
  in	
  RAM	
  while	
  app	
  is	
  in	
  use	
  or	
  tombstoned	
  
•  Really	
  easy	
  to	
  implement	
  store	
  key	
  value	
  pairs	
  
   in	
  PhoneApplica1onService.Current.State	
  
Example	
  
 protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
        {
            PhoneApplicationService.Current.State["key"] = "arvo";

            base.OnNavigatedFrom(e);
        }

        protected override void
OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            if (PhoneApplicationService.Current.State.ContainsKey("key"))
            {
                string value = (string) PhoneApplicationService.Current.State["key"];
            }
            base.OnNavigatedTo(e);
        }
When	
  values	
  are	
  lost?	
  
•  Open	
  app,	
  press	
  back	
  -­‐>	
  app	
  is	
  closed	
  -­‐>	
  data	
  
   lost	
  
•  Open	
  app,	
  press	
  start	
  -­‐>	
  press	
  back	
  -­‐>	
  data	
  is	
  
   there	
  
•  Open	
  app,	
  press	
  start	
  -­‐>	
  open	
  app	
  again	
  from	
  
   menu	
  -­‐>	
  data	
  lost	
  
•  Open	
  app,	
  long	
  press	
  back	
  -­‐>	
  switch	
  apps	
  -­‐>	
  
   long	
  press	
  back	
  to	
  switch	
  back	
  -­‐>	
  data	
  is	
  there	
  
Persistant	
  Storage:	
  Isolated	
  Storage	
  
•  Load	
  seings	
  when	
  app	
  launching	
  or	
  ac1va1ng	
  
•  Save	
  seings	
  when	
  app	
  deac1va1ng	
  or	
  closing	
  
•  Why?	
  
   –  program	
  should	
  also	
  save	
  applica1on	
  seings	
  during	
  
      the	
  Deac%vated	
  event	
  because	
  the	
  program	
  really	
  
      doesn’t	
  know	
  if	
  it	
  will	
  ever	
  be	
  resurrected.	
  And	
  if	
  it	
  is	
  
      resurrected,	
  it	
  should	
  load	
  applica1on	
  seings	
  during	
  
      the	
  Ac%vated	
  event	
  because	
  otherwise	
  it	
  won’t	
  know	
  
      about	
  those	
  seings.	
  	
  
Common	
  value	
  for	
  All	
  
public partial class App : Application
   {
      private String commonValue = "Default";

       public String CommonValue {
           set {
               commonValue = value;
           }
           get {
               return commonValue;
           }
       }
Usage	
  of	
  Common	
  Value	
  
private void button1_Click(object sender, RoutedEventArgs e)
       {
           App appRef = Application.Current as App;
           PageTitle.Text = appRef.CommonValue;
       }
App.xaml.cs:	
  
void SaveSettings()
   {
       IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
       settings["savedValue"] = CommonValue;
       settings.Save();
   }

   void LoadSettings()
   {
       string mydefault = "0";

       IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;

       if(settings.TryGetValue<string>("savedValue", out mydefault))
           CommonValue = (string) settings["savedValue"];
   }
App.xaml.cs:	
  
private void Application_Launching(object sender, LaunchingEventArgs e)
{
    LoadSettings();
}

private void Application_Activated(object sender, ActivatedEventArgs e)
{
    LoadSettings();
}

private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
    SaveSettings();
}

private void Application_Closing(object sender, ClosingEventArgs e)
{
    SaveSettings();
}

Weitere ähnliche Inhalte

Was ist angesagt?

Meandre Workbench Ws Jan 2009
Meandre Workbench Ws Jan 2009Meandre Workbench Ws Jan 2009
Meandre Workbench Ws Jan 2009
Loretta Auvil
 

Was ist angesagt? (11)

Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...
 
Meandre Workbench Ws Jan 2009
Meandre Workbench Ws Jan 2009Meandre Workbench Ws Jan 2009
Meandre Workbench Ws Jan 2009
 
Advanced RESTful Rails
Advanced RESTful RailsAdvanced RESTful Rails
Advanced RESTful Rails
 
Symfony3 w duecie z Vue.js
Symfony3 w duecie z Vue.jsSymfony3 w duecie z Vue.js
Symfony3 w duecie z Vue.js
 
Riding Apache Camel
Riding Apache CamelRiding Apache Camel
Riding Apache Camel
 
Laravel Tutorial PPT
Laravel Tutorial PPTLaravel Tutorial PPT
Laravel Tutorial PPT
 
Sel study notes
Sel study notesSel study notes
Sel study notes
 
JSF 2.0 Preview
JSF 2.0 PreviewJSF 2.0 Preview
JSF 2.0 Preview
 
Java server pages
Java server pagesJava server pages
Java server pages
 
Javascript laravel's friend
Javascript laravel's friendJavascript laravel's friend
Javascript laravel's friend
 
Creating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 ComponentsCreating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 Components
 

Ähnlich wie Windows Phone 7: Navigating Between Pages

iOS app dev Training - Session1
iOS app dev Training - Session1iOS app dev Training - Session1
iOS app dev Training - Session1
Hussain Behestee
 
commonXAMLControls.DS_Store__MACOSXcommonXAMLControls._.D.docx
commonXAMLControls.DS_Store__MACOSXcommonXAMLControls._.D.docxcommonXAMLControls.DS_Store__MACOSXcommonXAMLControls._.D.docx
commonXAMLControls.DS_Store__MACOSXcommonXAMLControls._.D.docx
monicafrancis71118
 
Windows Phone 8 Fundamental
Windows Phone 8 FundamentalWindows Phone 8 Fundamental
Windows Phone 8 Fundamental
Nguyên Phạm
 

Ähnlich wie Windows Phone 7: Navigating Between Pages (20)

MD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptMD-IV-CH-ppt.ppt
MD-IV-CH-ppt.ppt
 
Presentation - Windows App Development - II - Mr. Chandan Gupta
Presentation - Windows App Development - II - Mr. Chandan GuptaPresentation - Windows App Development - II - Mr. Chandan Gupta
Presentation - Windows App Development - II - Mr. Chandan Gupta
 
Intro to appcelerator
Intro to appceleratorIntro to appcelerator
Intro to appcelerator
 
[2015/2016] JavaScript
[2015/2016] JavaScript[2015/2016] JavaScript
[2015/2016] JavaScript
 
Tizen application inside out
Tizen application inside outTizen application inside out
Tizen application inside out
 
Os Haase
Os HaaseOs Haase
Os Haase
 
iOS app dev Training - Session1
iOS app dev Training - Session1iOS app dev Training - Session1
iOS app dev Training - Session1
 
Titanium appcelerator best practices
Titanium appcelerator best practicesTitanium appcelerator best practices
Titanium appcelerator best practices
 
commonXAMLControls.DS_Store__MACOSXcommonXAMLControls._.D.docx
commonXAMLControls.DS_Store__MACOSXcommonXAMLControls._.D.docxcommonXAMLControls.DS_Store__MACOSXcommonXAMLControls._.D.docx
commonXAMLControls.DS_Store__MACOSXcommonXAMLControls._.D.docx
 
23 silverlight apps on windows phone 8.1
23   silverlight apps on windows phone 8.123   silverlight apps on windows phone 8.1
23 silverlight apps on windows phone 8.1
 
React native
React nativeReact native
React native
 
Intro To webOS
Intro To webOSIntro To webOS
Intro To webOS
 
Windows Phone 8 Fundamental
Windows Phone 8 FundamentalWindows Phone 8 Fundamental
Windows Phone 8 Fundamental
 
Xamarin.Forms a different approach to cross platform natove mobile development
Xamarin.Forms a different approach to cross platform natove mobile developmentXamarin.Forms a different approach to cross platform natove mobile development
Xamarin.Forms a different approach to cross platform natove mobile development
 
Xamarin.Mac Introduction
Xamarin.Mac IntroductionXamarin.Mac Introduction
Xamarin.Mac Introduction
 
Titanium appcelerator my first app
Titanium appcelerator my first appTitanium appcelerator my first app
Titanium appcelerator my first app
 
Session 1
Session 1Session 1
Session 1
 
Apache cordova
Apache cordovaApache cordova
Apache cordova
 
Introduction to Palm's Mojo SDK
Introduction to Palm's Mojo SDKIntroduction to Palm's Mojo SDK
Introduction to Palm's Mojo SDK
 
Anatomy of android application
Anatomy of android applicationAnatomy of android application
Anatomy of android application
 

Mehr von Jussi Pohjolainen

Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
Jussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
Jussi Pohjolainen
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Jussi Pohjolainen
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platform
Jussi Pohjolainen
 

Mehr von Jussi Pohjolainen (20)

Moved to Speakerdeck
Moved to SpeakerdeckMoved to Speakerdeck
Moved to Speakerdeck
 
Java Web Services
Java Web ServicesJava Web Services
Java Web Services
 
Box2D and libGDX
Box2D and libGDXBox2D and libGDX
Box2D and libGDX
 
libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and Preferences
 
libGDX: Tiled Maps
libGDX: Tiled MapslibGDX: Tiled Maps
libGDX: Tiled Maps
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame Animation
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDX
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
libGDX: Scene2D
libGDX: Scene2DlibGDX: Scene2D
libGDX: Scene2D
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: User Input
libGDX: User InputlibGDX: User Input
libGDX: User Input
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDX
 
Android Threading
Android ThreadingAndroid Threading
Android Threading
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platform
 
Intro to Asha UI
Intro to Asha UIIntro to Asha UI
Intro to Asha UI
 

Kürzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Kürzlich hochgeladen (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 

Windows Phone 7: Navigating Between Pages

  • 1. Windows  Phone:     Naviga1on  between  Pages   Jussi  Pohjolainen   Tampere  University  of  Applied  Sciences  
  • 2. Programming  Environments   •  Two  programming  environments   –  XNA  –  for  games   –  Silverlight  –  non-­‐games   •  You  can  mix  some  of  the  libraries   •  When  crea1ng  a  project,  you  must  decide  if   you  are  doing  a  XNA  or  Silverlight  
  • 3. Silverlight:  for  apps  and  u1li1es   •  Silverlight  apps  are  combina1on  of  code  and   markup   •  Extensible  markup  language  (XAML),   pronounced  “zammel”  
  • 4. XNA:  for  games   •  High  performance  games:  2D  and  3D   •  Sprites  and  backgrounds  based  on  bitmaps   •  Moving  objects  around  screen,  polling  user   input,  built-­‐in  XNA  loop    
  • 5. Silverlight  files   •  Markup  files  and  “code  behind”  files:   –  App.xaml   –  App.xaml.cs   –  MainPage.xaml   –  MainPage.xaml.cs  
  • 6. App.xaml.cs:     App  wide  init,  startup  and  shutdown   namespace PhoneApp8 { public partial class App : Application { Par1al  class!  So   public App() another  App-­‐ class  must  be   { somewhere!   ... InitializeComponent(); ...
  • 7. App.xaml   •  App.xaml  and  App.xaml.cs  files  together  are   the  App-­‐class   •  How  can  .xaml  file  be  part  of  .cs?   –  During  compila1on   •  App.xaml  -­‐>  App.g.cs  !   •  g  stands  for  generated  
  • 8. App.g.cs   namespace PhoneApp8 { public partial class App : System.Windows.Application { private bool _contentLoaded; [System.Diagnostics.DebuggerNonUserCodeAttribute()] public void InitializeComponent() { if (_contentLoaded) { return; } _contentLoaded = true; System.Windows.Application.LoadComponent(this, new System.Uri("/ PhoneApp8;component/App.xaml", System.UriKind.Relative)); } } }
  • 9. App.xaml   <Application x:Class="PhoneApp8.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"> <!--Application Resources--> <Application.Resources> Store   </Application.Resources> resources:   colors,  styles..       <Application.ApplicationLifetimeObjects> <!--Required object that handles lifetime events for the application--> <shell:PhoneApplicationService Launching="Application_Launching" Closing="Application_Closing" Activated="Application_Activated" Deactivated="Application_Deactivated"/> </Application.ApplicationLifetimeObjects> </Application>
  • 10. MainPage.xaml.cs   •  When  app  is  ini1alized  the  App  class  opens  the  Main  Page   •  Again  par1al  class!  The  other  half  is  in  MainPage.xaml.cs     namespace PhoneApp8 { public partial class MainPage : PhoneApplicationPage { // Constructor public MainPage() { InitializeComponent(); } }
  • 11. MainPage.cs   •  Contains  visual  elements  of  the  main  page   PhoneApplicationFrame PhoneApplicationPage Grid named “LayoutRoot” StackPanel named “TitlePanel” TextBlock named “ApplicationTitle” TextBlock named “PageTitle” Grid named “ContentPanel”
  • 12.
  • 13. Xap  is  Zip   •  binDebug  dir  has  .xap  file   –  Pronounced  “zap”   •  This  is  the  file  to  be  deployed  to  phone  or   emulator  
  • 15. Basic  Structure   •  App  class  starts  the  app   •  PhoneApplicationFrame  instance  can  host   one  or  more  pages   •  PhoneApplicationPage  instances  are  the   pages  
  • 16. MainPage   namespace PhoneApp8 { public partial class MainPage : PhoneApplicationPage { // Constructor public MainPage() { InitializeComponent(); } … }
  • 17. Navigate   •  Naviga1on  is  based  on  XAML-­‐files  (like  .html   files  in  Web)   •  Use  Naviga1on  Service  to  navigate   –  Naviga1onService.Navigate(new  Uri("/ SecondPage.xaml",  UriKind.Rela1ve));   –  Naviga1onService.GoBack();  
  • 18. public partial class MainPage : PhoneApplicationPage { // Constructor public MainPage() { InitializeComponent(); } private void navigateButton_Click(object sender, RoutedEventArgs e) { NavigationService.Navigate(new Uri("/SecondPage.xaml", UriKind.Relative)); } }
  • 19. About  Naviga1on   •  Last-­‐in-­‐first-­‐out  =>  Stack   •  Phones  back  bueon  is  the  same  than   –  Naviga1onService.GoBack();   •  To  create  new  instance  of  the  page:   –  Naviga1onService.Navigate(new  Uri("/ MainPage.xaml",  UriKind.Rela1ve));  
  • 21. Possibili1es   •  Every  1me  you  navigate  to  new  page,  a  new   instance  is  created  =>  data  loss   •  Solu1ons   –  1)  Just  pass  data  across  pages   –  2)  PhoneApplica1onService:  data  in  memory  while   app  running   –  3)  IsolatedStorage:  persistant  storage    
  • 22. Page  1  to  Page  2   •  Pass  values  like  in  Web!   –   NavigationService.Navigate(new Uri("/ SecondPage.xaml?name=Jussi", UriKind.Relative));
  • 23. To  receive  the  parameters   protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { IDictionary<string, string> parameters = NavigationContext.QueryString; if (parameters.ContainsKey("name")) { PageTitle.Text = parameters["name"]; } base.OnNavigatedTo(e); }
  • 24. Give  values  back   protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e) { if (e.Content is MainPage) { MainPage reference = (e.Content as MainPage); reference.PageTitle.Text = "And we are back!"; } base.OnNavigatedFrom(e); }
  • 25. Basics   •  When  app  is  opened  from  Start  screen   –  App  is  launched   •  When  app  is  terminated  as  result  of  Back   –  App  is  closed   •  When  program  is  running  and  user  presses   start   –  App  is  deac1vated  -­‐>  tombstoned  state   •  When  program  is  navigated  back   –  App  is  ac1vated  -­‐>  back  from  tombstoned  state  
  • 26. public partial class App : Application { ... private void Application_Launching(object sender, LaunchingEventArgs e) { Debug.WriteLine("* Launch! *"); } private void Application_Activated(object sender, ActivatedEventArgs e) { Debug.WriteLine("* Activate! *"); } private void Application_Deactivated(object sender, DeactivatedEventArgs e) { Debug.WriteLine("* Deactivate! *"); } private void Application_Closing(object sender, ClosingEventArgs e) { Debug.WriteLine("* Closed! *"); }
  • 27. PhoneApplica1onService:   Store  Data  while  App  in  Memory   •  You  can  use  PhoneApplica1onService  to  store   data  in  RAM  while  app  is  in  use  or  tombstoned   •  Really  easy  to  implement  store  key  value  pairs   in  PhoneApplica1onService.Current.State  
  • 28. Example   protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e) { PhoneApplicationService.Current.State["key"] = "arvo"; base.OnNavigatedFrom(e); } protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { if (PhoneApplicationService.Current.State.ContainsKey("key")) { string value = (string) PhoneApplicationService.Current.State["key"]; } base.OnNavigatedTo(e); }
  • 29. When  values  are  lost?   •  Open  app,  press  back  -­‐>  app  is  closed  -­‐>  data   lost   •  Open  app,  press  start  -­‐>  press  back  -­‐>  data  is   there   •  Open  app,  press  start  -­‐>  open  app  again  from   menu  -­‐>  data  lost   •  Open  app,  long  press  back  -­‐>  switch  apps  -­‐>   long  press  back  to  switch  back  -­‐>  data  is  there  
  • 30. Persistant  Storage:  Isolated  Storage   •  Load  seings  when  app  launching  or  ac1va1ng   •  Save  seings  when  app  deac1va1ng  or  closing   •  Why?   –  program  should  also  save  applica1on  seings  during   the  Deac%vated  event  because  the  program  really   doesn’t  know  if  it  will  ever  be  resurrected.  And  if  it  is   resurrected,  it  should  load  applica1on  seings  during   the  Ac%vated  event  because  otherwise  it  won’t  know   about  those  seings.    
  • 31. Common  value  for  All   public partial class App : Application { private String commonValue = "Default"; public String CommonValue { set { commonValue = value; } get { return commonValue; } }
  • 32. Usage  of  Common  Value   private void button1_Click(object sender, RoutedEventArgs e) { App appRef = Application.Current as App; PageTitle.Text = appRef.CommonValue; }
  • 33. App.xaml.cs:   void SaveSettings() { IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings; settings["savedValue"] = CommonValue; settings.Save(); } void LoadSettings() { string mydefault = "0"; IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings; if(settings.TryGetValue<string>("savedValue", out mydefault)) CommonValue = (string) settings["savedValue"]; }
  • 34. App.xaml.cs:   private void Application_Launching(object sender, LaunchingEventArgs e) { LoadSettings(); } private void Application_Activated(object sender, ActivatedEventArgs e) { LoadSettings(); } private void Application_Deactivated(object sender, DeactivatedEventArgs e) { SaveSettings(); } private void Application_Closing(object sender, ClosingEventArgs e) { SaveSettings(); }