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]
[CODE]void OnActivated(object sender, ActivatedEventArgs e)
{
}
[/CODE]
but this is causing app to close.
Re: Which events fire on Page Activation - MainPage.xaml.cs
I think [I]OnActivated[/I] method is only for the Application itself, and it doesn't exist in the [URL="http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff402981(v=vs.105).aspx"]PhoneApplicationPage events list[/URL]
the [B]Loaded[/B] event may be the one you're looking for, it's fired when a page finish loading.
Edit : [B]OnNavigatedTo[/B] may do the job too.
Re: Which events fire on Page Activation - MainPage.xaml.cs
[QUOTE=Loukt;912982]the [B]Loaded[/B] event may be the one you're looking for, it's fired when a page finish loading.
Edit : [B]OnNavigatedTo[/B] may do the job too.[/QUOTE]
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
[B]PROBLEM,[/B]
When I move to [B]Background using Window key[/B] and Play some other Song/Music, the Background Music of the App stops as expected, but the AppBar Icon doesn't change to play.
[B]Where should I write the code that when I return back to my app, the AppbarIcon will act accordingly[/B]
[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);
}[/CODE]
Re: Which events fire on Page Activation - MainPage.xaml.cs
You should have mentionned that earlier and still [B]OnNavigatedTo[/B] will do the job.
when your app goes to dormant/tombstoned mode two event are fired =>the Page OnNavigatedFrom and the Application Deactivated
[img]http://i.msdn.microsoft.com/dynimg/IC531037.png[/img]
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);
}
}[/code]
You will find a similar case in this official doc link (step 6) [URL="http://msdn.microsoft.com/en-us/library/hh202978(v=vs.92).aspx"]How to: Play Background Audio for Windows Phone[/URL]
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 :o
Thank You so much Loukt