Software Input Panel

,

The Software Input Panel (SIP) appears automatically when focus is set to an editable control unless the device has a hardware keyboard ready to receive input, such as when a sliding keyboard is in its extended position. When the control loses focus because the user taps outside the edit control, scrolls a list, or presses the hardware Back button, the SIP is closed by sliding down off the bottom of the screen. If a phone has a hardware keyboard, and it is deployed, the SIP closes automatically.


Note

To detect when the hardware keyboard is deployed, subscribe to the Microsoft.Phone.Info.DeviceStatus.IsKeyboardDeployed event, discussed in Chapter 2, “Fundamental Concepts in Windows Phone Development.”



Tip

When using the emulator, a hardware keyboard can be simulated by pressing the PageUp button on your keyboard. The PageDown button disables the keyboard and reinstates the SIP.


Table 6.2 shows the 10 most commonly used context-specific SIP keyboard layouts. Input Scope is an InputScopeNameValue enumeration value described in the next section.

TABLE 6.2. SIP Keyboard Layouts

Image
SIP Dimensions

The onscreen keyboard is 336 pixels tall in portrait view and 256 pixels tall in landscape view. The text suggestion window, which appears above the keyboard, is 65 pixels tall in both page orientations.


Note

It is your responsibility to ensure that the control, where text is being entered, is above the SIP and in view.


Although it is not possible to define your own keyboard types or modify existing ones, you can switch the keyboard scheme of the SIP by using the TextBox.InputScope property. InputScope is discussed again in a moment.

Opening the SIP Programmatically

The SIP appears whenever a TextBox or PasswordBox gains focus. The SIP can, therefore, be opened programmatically by calling the Focus method of the control.

In some circumstances, such as when the primary purpose of a page is to allow the user to enter one or two pieces of information, it make sense to open the SIP as soon as the page loads. This can be done by subscribing to the PhoneApplicationPage.Loaded event and calling the Focus method of the control, as shown in the following excerpt:

public partial class ExamplesView : PhoneApplicationPage
{
    public ExamplesView()
    {
        InitializeComponent();
        Loaded += new RoutedEventHandler(ExamplesView_Loaded);
    }

    void ExamplesView_Loaded(object sender, RoutedEventArgs e)
    {
        autoFocussedTextBox.Focus();
    }
}


Best Practice

Expand the SIP automatically only if the application page has no more than two editable controls and the first editable control is a single-line edit box. Likewise, do not automatically expand the SIP if the page has content or controls that would be obscured behind the keyboard.


Dismissing the SIP Programmatically

If the TextBox loses focus (the user taps the display outside the TextBox, for example) the SIP is closed. To dismiss the SIP programmatically, however, you must shift focus to another control on the page. An elegant way of achieving this, and one that does not rely on another arbitrary control, is to focus the main content container of your page.

The following example shows the main content Grid for a page. The Grid contains a single TextBox as shown:

<Grid x:Name="ContentGrid" Grid.Row="1"
      IsTabStop="True">
    <TextBox x:Name="TextBox_Input" KeyUp="TextBox_KeyUp"  />
</Grid>

To allow the user to dismiss the SIP via the SIP Enter key, you can subscribe to the TextBox.KeyUp event. When the Enter key is detected, the SIP is dismissed by focusing the container. See the following excerpt:

void TextBox_KeyUp(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Enter)
    {
        this.Focus();
    }
}


Note

Make sure that the control to which you are shifting focus has its IsTabStop property set to true. When IsTabStop is false, the control is unable to receive focus, and hence will not cause the SIP to be closed. Most controls use true as the default IsTabStop value.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.242.131