on a brief blogging break

To our FAQ readers,  first of all Thanks for visiting and subscribing..

We are preparing for MIX11, where a lot of great Windows Phone stuff is happening.
Join us there face-to-face or follow it online, it will be fun and exciting..

We are so focused on MIX that we hardly sleep and have fallen behind on preparing FAQs to post; there fore we are taking a small break between now and MIX and will be back by April 15th…

Please stay tuned for more posts.  Send us your questions (and answers) if you think you have a FAQ question.  We won’t reply to all emails until 4/15, but the ones that we feel should be shared, will be posted here when we return..

Happy Windows Phone coding!!

Posted in Uncategorized | Leave a comment

what should I save to have a great Page navigation experience

I am already saving my data when I navigate across pages, but I hear I should save some of the view state (not just view model) to make it seamless to the user when a user comes back after tombstoning. What data should I save?

There is not an “all-inclusive list”. You should save what is meaningful and useful to your app. The most common examples include:

  • SelectedIndex for the pivot (if the page contains a pivot)
  • Scrolling position in a ListBox or any other ScrollViewer in the page.
  • Zoom levels and other transforms in a map control, picture viewer or any other control that supports manipulation
  • Uncommitted text in a TextBox. If the textbox is critical to the app (the tweet text in a Twitter app, for example) consider restoring text selection, caret position, and focus.
  • Element that had focus in a page (especially if it is a TextBox, which needs to show SIP
Posted in tombstoning, wp7 | Leave a comment

detecting tombstone for pages

Yesterday, I  showed how to detect if the application was truly tombstoned (terminated) or deactivated without termination.  I also mentioned, “sometimes, this is not all you need”;  what context is missing (when the flag is not enough)?

The answer relies on how you prepare a PhoneApplicationPage for tombstoning.   The recipe says:

  1. Save your state in OnNavigatedFrom ( )
  2. Load your state in OnNavigatedTo ()

Imagine you have a page1, and you navigate to page2. Sequence goes like this:

Page1.OnNavigatedFrom  () // saves state, does work
Page2.OnNavigatedTo () //
Press Back, will trigger
Page2.OnNavigatedFrom () //
Page1.OnNavigatedTo ()  // here is the magic place. We need to know if there was a tombstone since Page1.OnNavigatedFrom() was last called.  Unfortunately, the flag we set earlier does not tell us if there has been a tombstone since this page was created or serialized; that flag only tells us if there was a tombstone recently (but it could have been before or after our page was pushed to the back stack ). 

There are multiple approaches to deal with this.
The obvious one is to

  1. Set a flag on your page’s constructor.  If you set a “isnewPage” flag in your constructor, then
  2. During OnNavigatedTo you can check if your Page had state; if it does, then this must be a page after a tombstone, since page is being reconstructed but it has state.

Another approach is to assign tokens (or activationIds) to  your pages.

  1. If our application  keeps track of activationIds now when a page was constructed, we can assign an activationId to that page.
  2. Using yesterday’s flag to detect tombstones, we can detect deactivate->tombstone->activate sequences. When such a sequence happens,  we assign a new activationid to this run of the app. 
  3. now, when OnNavigatedTo () happens, we can check if the activationid  assigned by the app to this page (when the page was constructed) matches the activationid of the app.  if they do match, a tombstone has not happened.   if they do not match, then a tombstone must have happened while page was in the back stack.

Either approach works. All I am explaining is that for pages, listening to whether a tombstone happened is not enough.

Posted in tombstoning, wp7 | Leave a comment

detecting a tombstones

You mentioned not to use StartupMode to detect a tombstone, how should it be done?

If you just want to detect if a tombstone happened,  simply set a flag in your App’s handler to Deactivated event. 
If the value of the flag has not been reset (in Activated event) , then the app was not terminated. 
If the value of the flag has been reset (in Activated event) then app was terminated.


public partial class App : Application
    bool wasApplicationTerminated = true ;

    private void Application_Deactivated(object sender, DeactivatedEventArgs e)
            wasApplicationTerminated = false;

   private void Application_Activated(object sender, ActivatedEventArgs e)

       if ( wasApplicationTerminated== true ) 
              // real tombstone, new App instance                   
            // must have been a chooser that did not tombstone or a quick back.



All that said, the above check is not always useful; you most often will want to know more than whether app was tombstoned; you want to know if it was tombstoned since your pages were NavigatedFrom ..  Stay tuned for that tomorrow..

Posted in tombstoning, wp7 | Leave a comment


I am trying to use PhoneApplicationService.Current.StartupMode to detect if my application is tombstoned, but it seems to not detect deactivations that don’t tombstone.
What gives?

You are right; currently StartupMode does not convey whether a deactivation lead to a true tombstone (aka process termination).   The StartupMode flag just tells you how the last time the actual process was started happens.

Here is an example on how it is not reliable.

  1. Launch process ( mode will be Launch)
  2. Show a Chooser (such as PhotoChooserTask) that does not tombstone.
  3. Click Back to get back to the app;  StartupMode will still be Launch – arguably this is right since process was not terminated.

Now, try different sequence:

  1. Launch process ( mode will be Launched)
  2. Press start button to tombstone the application
  3. Click Back  — StartupMode will be Activate 
  4. Show a Chooser (such as PhotoChooserTask) that does not tombstone.
  5. Click Back to get back to the app, StartupMode will now remain as Activate – arguably this is right since process was not terminated; but now the information is useless because you will not know if process was tombstoned or not.

Lesson learned: don’t rely on StartupMode to try to detect if a process was tombstoned.


Posted in tombstoning, wp7 | 2 Comments

PhoneApplicationPage.State limitations

I am serializing data in my PhoneApplicationPage.State dictionary and I see ‘weird’ errors when I insert a lot of data. Is this a known issue?

Yes. Page.State has weird ‘limitations’. I have not seen these documented to exact limits, and I see them be a combination of circumstances, here is what I have observed:

  1. If you insert more than > 2 MB of data into PhoneApplicationPage.State, your navigations will see RootFrame.NavigationFailed fire. The NavigationFailedEventArgs will have a weird error about IAccessControl::IsAccessPermitted, and a 0×80040204 Hresult.
  2. If you insert smaller chunks of data into PhoneApplicationPage.State, but you have a back stack with enough pages to exceed again the same > 2.5  MB, you will get NavigationFailed again, different error: Unable to obtain the client’s security blanket; the Hresult is 0×80040205

Afaik, there is not much you can do to prevent these. The workaround is not to store this much data in PhoneApplicationPage.State. You can use IsolatedStorage instead. I recommend you serialize these as binary (yes, a little work, but much better performance) if you have a lot of data to save.

Posted in tombstoning, wp7 | Leave a comment

pushpin virtualization

I am using the map control with lots, lots of data. I noticed the maps are a bit slow to draw.
How can I virtualize the pushpins (and focus around a viewpoint)?

There is not out-of-the-box support for pushpin virtualization in the map control.
You can handle the ViewChanged event of the map control and there collapse or remove the pins that you don’t need.

Posted in maps, wp7 | Leave a comment

prevent zoom on a map

I am using the bing maps control in my app. I want to prevent the user from zooming in or out. I hid the zoom bar, but cant’ disable gestures.  How can I prevent zoom?

You can try hooking the ViewChangeStart event and resetting the zoom level there. It is not too pretty but it works.

Posted in maps, wp7 | Leave a comment

my app requires owner identity and I can’t tell why

I submitted the app to marketplace, and the required capabilities assigned to it by the system are that it requires “owner identity”.  I am not doing anything to access user data or identity. is this a problem with certification process?

Most likely not.  The ad control is the most common culprit. it uses the anonymized LiveId off the UserExtendedProperties.

Posted in ads, controls, wp7 | 2 Comments

ad control outside the US

My understanding is that the ad control of pubcenter does not show ads outside of the US.Is there any way for me to detect this?

Posted in ads, wp7 | Tagged | Leave a comment