DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report

Input box? On Windows Phone 7? Indeed.

Denzel D. user avatar by
Denzel D.
·
Nov. 03, 10 · Interview
Like (0)
Save
Tweet
Share
13.35K Views

Join the DZone community and get the full member experience.

Join For Free

If you are a seasoned Windows developer, you probably are familiar with the concept of an input box - basically, a modal windows that pops up to prompt the user to enter a single value that is later on returned to the application. In .NET, this concept was implemented as a part of the VB.NET-specific part of the framework and when it came to the point when it should have been used in a C# application, the only choices would be either referencing VB.NET libraries or implementing your own class.

Windows Phone 7 doesn't support any of the regular Windows objects, therefore importing a VB.NET library won't make any sense, simply because it wasn't deisgned to be working on the mobile platform. What many developers (especially those who just started working on their applications) don't know is that there is a built-in implementation of an input box right in the SDK.

It is not that obvious as it might look, especially if the main development is done in Silverlight, since the method I am talking about is included in the XNA part of the SDK. In your Silverlight project, add a reference to Microsoft.Xna.Framework and Microsoft.Xna.Framework.GamerServices.

Now, whenever you need to trigger the input box, you can easily call this line of code:

Guide.BeginShowKeyboardInput(Microsoft.Xna.Framework.PlayerIndex.One, "Title", "Description", "DefaultText", new AsyncCallback(GetString),null);

As you can see, I can set the title, description and the default text for the box. Now, notice one more thing - the operation requires a callback method, and in this case it is called GetString. What I have to do in that method is call EndShowKeyboardInput to signal that the input operation is done and get the actual string:

void GetString (IAsyncResult res)
{
string test = Guide.EndShowKeyboardInput(res);
Debug.WriteLine(test);
}

So when the page is shown (or whenever you decide to display the box), you should see something like this:

Since I am displaying the result in the Output window, once I click OK, the text is passed to Debug.WriteLine and I can see it displayed:

No text is returned if the user clicks on Cancel, so if the input value is critical, you should check against null and empty returned values.

 

Windows Phone

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Building a REST API With AWS Gateway and Python
  • What Are the Different Types of API Testing?
  • Cloud Performance Engineering
  • Java Concurrency: LockSupport

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: