×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Nokia Developer Champion
    Join Date
    Nov 2012
    Location
    Karachi
    Posts
    89

    Which events fire on Page Activation - MainPage.xaml.cs

    In MainPage.xaml.cs

    I am using following code

    Code:
    PhoneApplicationService.Current.Activated += new EventHandler<ActivatedEventArgs>(OnActivated);
    Code:
    void OnActivated(object sender, ActivatedEventArgs e)
    {
    }
    but this is causing app to close.

  2. #2
    Nokia Developer Champion
    Join Date
    Sep 2012
    Location
    Morocco
    Posts
    297

    Re: Which events fire on Page Activation - MainPage.xaml.cs

    I think OnActivated method is only for the Application itself, and it doesn't exist in the PhoneApplicationPage events list

    the Loaded event may be the one you're looking for, it's fired when a page finish loading.

    Edit : OnNavigatedTo may do the job too.

  3. #3
    Nokia Developer Champion
    Join Date
    Nov 2012
    Location
    Karachi
    Posts
    89

    Re: Which events fire on Page Activation - MainPage.xaml.cs

    Quote Originally Posted by Loukt View Post
    the Loaded event may be the one you're looking for, it's fired when a page finish loading.

    Edit : OnNavigatedTo may do the job too.
    Neither Loded nor OnNavigatedTo is doing the job.

    I have a Background Music and An Appbar Icon of that Bg Music.
    When I play the Music, the Appbar Icon changes to Stop
    When I Stop the Muisc, the Appbar Icon changes to Play

    Suppose Background Music is currently playing, and Appbar Icon is Stop,
    Now

    PROBLEM,
    When I move to Background using Window key and Play some other Song/Music, the Background Music of the App stops as expected, but the AppBar Icon doesn't change to play.


    Where should I write the code that when I return back to my app, the AppbarIcon will act accordingly
    Code:
     if (PlayState.Playing == BackgroundAudioPlayer.Instance.PlayerState)
                {
                    ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IconUri = new Uri("/Images/appbar/transport.pause.png", UriKind.RelativeOrAbsolute);
                }
                else
                {
                    ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IconUri = new Uri("/Images/appbar/transport.play.png", UriKind.RelativeOrAbsolute);
                }

  4. #4
    Nokia Developer Champion
    Join Date
    Sep 2012
    Location
    Morocco
    Posts
    297

    Re: Which events fire on Page Activation - MainPage.xaml.cs

    You should have mentionned that earlier and still OnNavigatedTo will do the job.
    when your app goes to dormant/tombstoned mode two event are fired =>the Page OnNavigatedFrom and the Application Deactivated



    and when you activate your app back, it goes to => the Application Activated and Page OnNavigatedTo

    so basically you should just write the code in the OnNavigatedTo method
    Code:
     protected override void OnNavigatedTo(NavigationEventArgs e){
          if (PlayState.Playing == BackgroundAudioPlayer.Instance.PlayerState)
                {
                    ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IconUri = new Uri("/Images/appbar/transport.pause.png", UriKind.RelativeOrAbsolute);
                }
                else
                {
                    ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IconUri = new Uri("/Images/appbar/transport.play.png", UriKind.RelativeOrAbsolute);
                }
    }
    You will find a similar case in this official doc link (step 6) How to: Play Background Audio for Windows Phone

  5. #5
    Nokia Developer Champion
    Join Date
    Nov 2012
    Location
    Karachi
    Posts
    89

    Re: Which events fire on Page Activation - MainPage.xaml.cs

    It wasn't working last night.
    It works today.
    what kind of sorcery is this

    Thank You so much Loukt

Similar Threads

  1. Using a .xaml page as PivotItem Content
    By Kunal Prime in forum Windows Phone General
    Replies: 10
    Last Post: 2013-03-12, 05:05
  2. How crate a "PhoneApplicationPage" not by XAML file on Window Phone 7?
    By water1984609 in forum Windows Phone General
    Replies: 5
    Last Post: 2011-12-22, 10:00
  3. FIRE Key on E5 or E72
    By lover91 in forum Mobile Java General
    Replies: 2
    Last Post: 2010-12-12, 08:25
  4. View activation events
    By TheLich in forum Symbian
    Replies: 9
    Last Post: 2010-07-26, 10:05
  5. Replies: 2
    Last Post: 2009-01-21, 05:13

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×