Windows Phone 7 CTP Refresh and InputScope

If you haven’t heard the Windows Phone 7 CTP April Refresh has been released.  Prepping for my Toronto CodeCamp Session tomorrow I found an issue with setting an InputScope to TextBox.  I am basically doing the same demo Mike Harsh did at MIX10 where all InputScopeNameValues were used to populate a ListBox and then dynamically change the InputScope on a TextBox.

Pre April CTP you could use the following code

textBox1.InputScope = new System.Windows.Input.InputScope() { Names = new InputScopeName() { NameValue = InputScopeNameValue.AddressCity} };

with the April CTP for Windows Phone 7 this breaks now and gives an error of  “Property or indexer ‘Names’ cannot be assigned to — it is read only”

Don’t know if it’s a bug or not but there is an alternative as follows.

textBox1.InputScope = new System.Windows.Input.InputScope() ;
InputScopeName isn = new InputScopeName() { NameValue = InputScopeNameValue.AddressCity };

Peter Foot also mentioned that you can use XAML to make this happen:

<TextBox Height="32" HorizontalAlignment="Left" Margin="324,70,0,0"
Name="textBox1" Text="TextBox" VerticalAlignment="Top" Width="137" InputScope="Text" />

and then dynamically set it with the following:

((InputScopeName)textBox1.InputScope.Names[0]).NameValue = val;

This is expected with CTPs, just wish it didn’t happen the day before a presentation!

Warning: count(): Parameter must be an array or an object that implements Countable in /nfs/c07/h02/mnt/110221/domains/ on line 405

Leave a Reply