Derik Whittaker

Syndication

News


Closing the Virtual Keyboard (SIP) and forcing binding in WP7

One key UX concept when working with the WP7 is making data entry easy for the user.  When entering a text box on WP7 you are presented with the virtual keyboard (aka SIP – Soft Input Panel).  The trick is allowing the user to close this keyboard without having to do something special (yes using the back button will close the keyboard, but this may not be as intuitive to the users)

The first thing we should look at is how to close the SIP (this technique comes from here).  The basic idea around dismissing the keyboard is to add an event handler and check for certain key presses occurring.

How Code to close the keyboard

// Binding which registered the KeyDown event
≶TextBox Name="RegistrationKeyTextBox" Text="{Binding RegistrationKey, Mode=TwoWay}" Margin="12,0" KeyDown="RegistrationKeyTextBox_KeyDown"/>

// Event Handler
private void RegistrationKeyTextBox_KeyDown( object sender, KeyEventArgs e )
{
    if ( e.Key == Key.Enter )
    {
        // because binding does not occure untile you leave the box we want to force it here
        ( (TextBox)sender ).ForceBinding();

        // swap focus back to the screen
        Focus();

        ViewModel<DeviceRegistrationViewModel>().RegisterDeviceCommand.Execute( null );
    }
}

Take notice in the code above the extension method .ForceBinding() this is the code we can use to force the binding to fire on the text box.  You can also notice that I am calling into my ViewModel to execute the ‘Register Device’ actions.

In order to invoke the binding you will need the code below (hey, there may be other ways but this works)

Code to invoke binding

public static class TextBoxExtensions
{
    public static void ForceBinding( this TextBox textBox )
    {            
        var binding = textBox.GetBindingExpression( TextBox.TextProperty );
        if ( binding != null ) { binding.UpdateSource(); }
    }
}

The above we are simply calling the updateSource method which fires the binding. 

As you can see you do have to provide a bit of coding (which sucks) to get this type of user experience but IMO it is well worth it.

Till next time,

*** If there is a better way I could not find it online ***


Posted 12-20-2010 10:25 AM by Derik Whittaker

[Advertisement]

Comments

Joshua Sigar wrote re: Closing the Virtual Keyboard (SIP) and forcing binding in WP7
on 12-20-2010 1:26 PM

I don't think pressing Enter is intuitive either. Pressing Enter is ideally to submit a form. I still think adding "hide keyboard" key in SIP (like Android's) is the proper solution.

http://links.ginktage.com wrote Closing the Virtual Keyboard (SIP) and forcing binding in WP7 - Derik Whittaker - Devlicio.us - Just the Tasty Bits
on 12-30-2010 5:32 AM

Closing the Virtual Keyboard (SIP) and forcing binding in WP7 - Derik Whittaker - Devlicio.us - Just the Tasty Bits

The Gold Rush wrote re: Closing the Virtual Keyboard (SIP) and forcing binding in WP7
on 12-31-2010 4:35 AM

<a href="filmspack.com/.../">The gold rush download</a> movie

Alcazzarre wrote re: Closing the Virtual Keyboard (SIP) and forcing binding in WP7
on 03-15-2011 10:49 AM

Maybe Alcazzarre could help you to solve your problems? You'r welcome pal.

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)