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?
Attached is a simple demo with source on how this is done.
Comments
brian dunnington
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?
lumaLilt
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
I''ll take a look at the formatting and I''ll do a new post.
Juliana
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
Can you email me your app and I''ll take a look.
Juliana
I''m just using your code without any modification. I''m running it on my phone with NoDo installed.
Juliana
Hi Chris, I managed to fix the error by creating my own style with Blend. Thanks for your help anyway :)