A group blog from members of the VB team
In our last post, I explained how to create a settings page for Windows Phone 7. In this blog post, I want to share a sample that will help you to create a keyboard input scope application for Windows Phone 7. This application will have the feature that allows you to change the input scope of the on-screen keyboard to one of the many built-in options. This sample contains code for three different ways of changing the on-screen keyboard.
I will now demonstrate how easy it is to create a keyboard input scope application for Windows Phone 7, using Visual Basic for Windows Phone Developer Tools. The keyboard input scope application can be created in 4 simple steps as follows:
Prerequisites:
To create a keyboard input scope application for Windows Phone 7 application, let’s follow the 4 simple steps mentioned earlier:
<Grid x:Name="LayoutRoot" Background="Transparent">
<!--Pivot Control-->
<controls:Pivot Title="Keyboard Test App" >
<!--Pivot item one-->
<controls:PivotItem Header="all">
<StackPanel Height="Auto" Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- These text boxes use the short form to set the InputScope -->
<!-- You must know the name of the InputScope that you want to use -->
<TextBlock Text="your name" Foreground="{StaticResource PhoneAccentBrush}" Style="{StaticResource PhoneTextLargeStyle}" />
<TextBox InputScope="PersonalFullName" Name="txtName" Height="71" Width="460" />
<TextBlock Text="what country are you from?" Foreground="{StaticResource PhoneAccentBrush}" Style="{StaticResource PhoneTextLargeStyle}" />
<TextBox InputScope="AddressCountryName" Name="txtCountry" Height="71" Width="460" />
<TextBlock Text="your number" Foreground="{StaticResource PhoneAccentBrush}" Style="{StaticResource PhoneTextLargeStyle}" />
<TextBox InputScope="Number" Name="txtNumber" Height="71" Width="460" />
<!-- This text box uses the long form to set the InputScope -->
<!-- You can use intellisense to get the name of the InputScope that you want to use -->
<!-- Put the cursor between the quotation marks after NameValue="" -->
<!-- Press the space key and intellisense will list the options -->
<!-- USE THIS TEXT BOX TO TEST THE DIFFERENT KEYBOARDS -->
<TextBlock Text="(set scope in the XAML)" Foreground="{StaticResource PhoneSubtleBrush}" Style="{StaticResource PhoneTextLargeStyle}" />
<TextBox Name="txtChoose" Height="71" Width="460" >
<TextBox.InputScope>
<InputScope>
<InputScopeName NameValue="Default" />
</InputScope>
</TextBox.InputScope>
</TextBox>
<Button Content="view" Click="button_Click" Height="71" Width="160" />
</StackPanel>
</controls:PivotItem>
<!--Pivot item two-->
<controls:PivotItem Header="about">
<TextBlock Text="your email" Foreground="{StaticResource PhoneAccentBrush}" Style="{StaticResource PhoneTextLargeStyle}" />
<TextBox InputScope="EmailNameOrAddress" Name="txtEmail" Height="71" Width="460" />
<TextBlock Text="your favorite website" Foreground="{StaticResource PhoneAccentBrush}" Style="{StaticResource PhoneTextLargeStyle}" />
<TextBox InputScope="Url" Name="txtWebsite" Height="71" Width="460" />
<TextBlock Text="call your best friend" Foreground="{StaticResource PhoneAccentBrush}" Style="{StaticResource PhoneTextLargeStyle}" />
<TextBox InputScope="TelephoneNumber" Name="txtFriend" Height="71" Width="460" />
<!-- The input scope for this text box is set by code -->
<!-- The code is in the MainPage_Loaded event -->
<TextBlock Text="(set scope in the code)" Foreground="{StaticResource PhoneSubtleBrush}" Style="{StaticResource PhoneTextLargeStyle}" />
<TextBox Name="txtSetByCode" Height="71" Width="460" />
<!--Pivot item three-->
<controls:PivotItem Header="you">
<TextBlock Text="how are you feeling today?" Foreground="{StaticResource PhoneAccentBrush}" Style="{StaticResource PhoneTextLargeStyle}" />
<TextBlock Text="use the smiley button!" Foreground="{StaticResource PhoneAccentBrush}" Style="{StaticResource PhoneTextLargeStyle}" />
<TextBox InputScope="Chat" Name="txtFeeling" Height="194" Width="460" />
</controls:Pivot>
</Grid>
Your application now looks like this:
Partial Public Class MainPage
Inherits PhoneApplicationPage
' Constructor
Public Sub New()
InitializeComponent()
End Sub
End Class
Private Sub MainPage_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles Me.Loaded
Dim scope As New InputScope
Dim name As New InputScopeName
name.NameValue = InputScopeNameValue.Number
scope.Names.Add(name)
txtSetByCode.InputScope = scope
Private Sub button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim sb As New System.Text.StringBuilder
sb.AppendLine("What I know about you:")
sb.AppendLine(txtName.Text)
sb.AppendLine(txtCountry.Text)
sb.AppendLine(txtNumber.Text)
sb.AppendLine(txtEmail.Text)
sb.AppendLine(txtWebsite.Text)
sb.AppendLine(txtFriend.Text)
sb.AppendLine(txtFeeling.Text)
MessageBox.Show(sb.ToString())
There you are! Now your keyboard input scope application for Windows Phone 7 is ready! You just need to build and debug the application.
Note: To stop debugging the application, select Debug > Stop Debugging.
Finally, to submit your application to the market place, you can refer to upload your application walkthrough.
Congrats! Buenos! You have successfully created a keyboard input scope application for Windows Phone 7, that too in just 4 simple steps! You can find the full source code for the settings page application here.
GENIOUS