How to use the default TextBox control with Copy & Paste

After my post the other night about how the forthcoming Windows Phone update would support Copy & Paste automagically, there has been some who don’t agree with the implementation. 

I, for one, agree with how they’ve singled out the TextBox control for native support.  Brian Dunnington posted his objections saying that it would unnecessarily invoke the SIP (Software Input Panel) and the keyboard would be displayed.  This isn’t the case.

There is a simple property on the TextBox, which, if set, won’t invoke the SIP when the textbox is focused.  When  IsReadOnly is set to “true”, the phone will use the default ReadOnly style shipped with Windows Phone.  Below is a photo of a read-only TextBox with a custom style.  Notice when it’s focused, there is no keyboard popup?

IMG_0557

Attached is a simple demo with source on how this is done.

windows-phone-7
Posted by: Chris Walsh
Last revised: 19 Apr, 2011 10:23 AM History

Comments

brian dunnington
brian dunnington
27 Jan, 2011 03:36 PM

That is a good solution for preventing the SIP from popping up.

Do you have any suggestions for handling formatted text (Runs)? Or clickable links embedded within the text?

27 Jan, 2011 07:24 PM

I have used a custom-styled TextBox in read-only mode versus a TextBlock in a published app just for the built-in TextChanged event. Just style it to look more like a TextBlock with the correct background color, no border and correct foreground color.

Chris
Chris
29 Jan, 2011 10:36 PM

I''ll take a look at the formatting and I''ll do a new post.

30 Mar, 2011 06:50 PM

Hi Chris,

I''m getting an MS.Internal.WrappedException "Unspecified Error" both when running your sample code and when using your TextBox style in my code. Any idea what could be happening?

Chris
Chris
30 Mar, 2011 08:56 PM

Can you email me your app and I''ll take a look.

31 Mar, 2011 05:00 AM

I''m just using your code without any modification. I''m running it on my phone with NoDo installed.

31 Mar, 2011 05:44 PM

Hi Chris, I managed to fix the error by creating my own style with Blend. Thanks for your help anyway :)

Your Comments

Used for your gravatar. Not required. Will not be public.
Posting code? Indent it by four spaces to make it look nice. Learn more about Markdown.

Preview