In MainPage.xaml.cs
I am using following code
Code:PhoneApplicationService.Current.Activated += new EventHandler<ActivatedEventArgs>(OnActivated);but this is causing app to close.Code:void OnActivated(object sender, ActivatedEventArgs e) { }
In MainPage.xaml.cs
I am using following code
Code:PhoneApplicationService.Current.Activated += new EventHandler<ActivatedEventArgs>(OnActivated);but this is causing app to close.Code:void OnActivated(object sender, ActivatedEventArgs e) { }
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.
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); }
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
You will find a similar case in this official doc link (step 6) How to: Play Background Audio for Windows PhoneCode: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); } }
It wasn't working last night.
It works today.
what kind of sorcery is this
Thank You so much Loukt