Sunday, February 19, 2012

Issue with circular navigation in Windows Phone 7

The good management of the back button is really important: for example, a valid application must quit when you press the back button when you are on its start page. Other constraints must be respected like when you press the back button when a dialog is open (like a ListPicker control), you have to cancel the back behaviour and close the dialog...

For some applications, there's not necessary to think about it because the default behavior is well suited. But for other applications, it will sometimes be necessary to make some changes.

I will show an example of my application (Blind Friends)... If an user wants to play, he will go through these pages:

> >
>

Imagine that the user presses the "back to main menu" at the end of the game, I'll use NavigationService.Navigate(Uri source) to bring him back to home. That will work but if the user presses the back button once he is on the home page, the application will go to the score page because this is the previous page in the navigation stack... My application can be validated with this issue because it must be closed when the user presses the back button on this page.

To regain the normal behaviour, I have modified the URI in NavigationService.Navigate(Uri source):

   1:  NavigationService.Navigate(new Uri("/Pages/MainPage.xaml?homeFromPageScore=true", UriKind.Relative))

And in the codebehind of my home page:

   1:  protected override void OnNavigatedTo(NavigationEventArgs e)
   2:  {
   3:      base.OnNavigatedTo(e);
   4:   
   5:      if (e.NavigationMode == NavigationMode.New && NavigationContext.QueryString.ContainsKey("homeFromPageScore"))
   6:      {
   7:          NavigationService.RemoveBackEntry();
   8:          NavigationService.RemoveBackEntry();
   9:          NavigationService.RemoveBackEntry();
  10:          NavigationService.RemoveBackEntry();
  11:      }
  12:  }

With this workaround, you clean the navigation stack as many times as necessary (neither too much nor too little...). In my case, I'm sure on the number of time I have to remove an element in the navigation stack and the behaviour requested by Microsoft is respected.

Saturday, February 18, 2012

Issue with Chinese (zh) and Windows Phone

(FYI: I'm speaking about the Windows Phone SDK 7.1, these information can change...)

For my first Windows Phone application, I had an issue with the Chinese language... In the ASP.NET MVC version, I use a resource file like this BlindFriendsResource.zh.resx and that works!

So I wanted to keep the same file for the mobile version and... the application was launched in its default language (English).

After some research, I found the solution! I created two files: BlindFriendsResource.zh-CN.resx (Simplified) and BlindFriendsResource.zh-TW (Traditional). These two files correspond to the both supported  languages in Windows Phone.

Using "zh" only will not work for the Chinese language but using "fr" will work for a belgian  person (French speaker: fr-BE) or a french person (fr-FR)... So, finaly, you can see here the list of my resources files:

- BlindFriendsResource.resx
- BlindFriendsResource.es.resx
- BlindFriendsResource.fr.resx
- BlindFriendsResource.nl.resx
- BlindFriendsResource.pt.resx
- BlindFriendsResource.zh-CN.resx
- BlindFriendsResource.zh-TW.resx

I hope that information can be useful for someone ;-)

Tuesday, February 14, 2012

Blind Friends is now on Windows Phone 7

Blind Friends (my Facebook game) is now on Windows Phone 7 market:



I used again the Facebook C# SDK (http://facebooksdk.codeplex.com/) for this mobile application and the ASP.NET MVC version communicates with the WP7 version with some Json...

I will write one or two articles on the development of Blind Friends WP7 (Facebook logout, circular navigation issue, ...)

Découvrez le Nokia Lumia 900 avec MonWindowsPhone

Wednesday, January 25, 2012

Windows Phone 7 emulator and computer keyboard

I'm currently working on the Windows Phone version of Blind Friends and I'm using the Facebook C# SDK Framework (like the ASP.NET MVC version).

I had to debug the login page and I quickly got bored of writing my email/password in the emulator... If you have a Windows Phone device, you can enter these information with your fingers but if you debug with the emulator, you maybe want to use your computer's keyboard.

By default, the keyboard is not enabled but activating it on your development computer is easy:

  • to enable the keyboard: press the PAGE UP key (or PAUSE key)
  • to disable the keyboard: press the PAGE DOWN key (or PAUSE key, again)

It's fast and convenient, but some details may annoy you... For example, if you enable the keyboard, the emulator will not support the orientation changes. You have to disable the keyboard, and then rotate the emulator.

For more information on the keyboard mapping: http://msdn.microsoft.com/en-us/library/ff754352(v=VS.92).aspx

Tuesday, January 24, 2012

Windows Azure and Application Pool Timeouts

This article may help you if you use Windows Azure and you want your application to always responds as quickly even after a long period without use...

With default parameters, your app pool is shut down after 20 minutes of inactivity and your application will take a bit more time to respond.

You can simply change the settings if you want your application pool is never shut down:

- First step: create a new folder called "tasks" at the root of your Web Project and add a new file called "timeout.cmd" with this line of command:

   1:  %windir%\system32\inetsrv\appcmd set config -section:applicationPools -applicationPoolDefaults.processModel.idleTimeout:00:00:00

Once the file created, you need to put the "Copy to Output Directory" property to "Copy Always".


- Second step: add this into ServiceDefinition.csdef (at same level than "<Sites>", "<Endpoints>", ...):

   1:  <Startup>
   2:        <Task commandLine="tasks\timeout.cmd"
   3:              executionContext="elevated" />
   4:  </Startup>


You can find the code here: