Migrating to Mango – Developer View. Part 4

In one of the previous parts of this series I formulated a hypothesis that the Mango emulator reads the application profile and decides whether to use WP7.0 or WP7.1 libraries. Below I’ll give a proof for this statement. I’ll even show that the Visual Studio does the same when compiling a project.
Let me go step by step and start with the description of the test application that served as a laboratory.
One day I noticed that Mango apps can use better number keyboard.

TextBox with InputScopeNameValue.Number, WP7.0

TextBox with InputScopeNameValue.Number, WP7.1

This caught my attention and I coded an app that tests all possible keyboards. Let’s start by explaining what the app does.
The keyboard is typically defined in Xaml such as for example
<TextBox InputScope=”Number”/>.
The Xaml syntax is simple and intuitive, yet it is not suited for my purposes – I wanted to find ALL differences in the keyboard treatment
The C# equivalent of the above Xaml code is here:
     var scopeName = new InputScopeName() { NameValue =                                          InputScopeNameValue.Number };
     var keyboard = new InputScope();
     keyboard.Names.Add( scopeName );
     TextBox box = new TextBox() { InputScope = keyboard }
(If you ask why Xaml is so much simpler, then it uses InputScopeNameConverter that does the hard work by constructing InputScope from a string.)
The enumeration InputScopeNameValue contains all possible keyboard types. Apparently, the solution would be to construct one TextBox for every possible keyboard. The problem was that InputScopeNameValue is a long enum and I was a bit lazy. Moreover, I was not sure if the enum definition did not change in Mango. (Well, at this point I theoretically admitted this, but could not imagine how this would be done.) I decided to enumerate InputScopeNameValue values by code. .Net offers nice method for this – Enum.GetValues. Unfortunately, this method is stripped off from Silverlight libraries.
No problem, this code does the job:
     public static IEnumerable GetEnumValues(Type enumeration)
          IList<object> enums = new Collection<object>();
          if (enumeration.IsEnum)
               foreach (FieldInfo fieldInfo in enumeration.GetFields(BindingFlags.Static |                  BindingFlags.Public))
          return enums;
The rest was straightforward – I created one TextBox for each keyboard type and added it to a grid together with a label (a TextBlock)
describing the keyboard used. Here is the code
     foreach (InputScopeNameValue scope in                                                                  GetEnumValues(typeof(InputScopeNameValue)))
          TextBlock txt = new TextBlock() { Text=scope.ToString(), FontSize=15 };
          var keyboard = new InputScope();
          var scopeName = new InputScopeName() {NameValue = scope};
          keyboard.Names.Add( scopeName );
          TextBox box = new TextBox() {InputScope = keyboard};
          // Omitted code: Adding txt/box element to the grid
Looks like we are ready. We’ll see in the next part whether it is really so.
Next part is coming soon…
About the author
Jan Slodicka
Programming for over 30 years. Covered several desktop platforms and programming languages. Since 2003 working for Resco on mobile technologies – Palm OS, Windows Mobile, Windows Phone 7, Android. You can contact me at jano (at) resco (dot) net.

Follow our blog

Enter your email address to follow this blog and receive notifications of new posts by email.