9

As the new (January 2011) Update to the Windows Phone Developer Tools adds support for Cut and Paste, can this be used programmatically in code?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Matt Lacey
  • 65,560
  • 11
  • 91
  • 143
  • 1
    hahah, are we all now asking/answering our own WP7 questions right away like Dennis (http://stackoverflow.com/users/303696/dennis-delimarsky)? – Todd Main Feb 05 '11 at 17:58
  • 2
    Actually, Matt started it. To avoid questions asked later on, it is easier to direct users to a self-answered one. After all, it's a knowledge base. – Den Feb 05 '11 at 18:57
  • Based on recent activity I thought someone was bound to ask this. Also, it has already been asked on Twitter countless times. AFAIAW, asking and answering a question has always been acceptable. Having definitive answers to specific programming related questions has always been a goal of SO anyway. – Matt Lacey Feb 06 '11 at 22:02
  • Is there any update here for Mango? – Michael Donohue Oct 05 '11 at 17:31
  • @Michael updated answer below – Matt Lacey Oct 06 '11 at 08:35

1 Answers1

10

No.

The January 2011 update does not include programatic access to the clipboard (or any new APIs). The clipboard can only be accessed by the user to cut and paste text. Yes, only text can be cut, copied and pasted.

Cut and paste functionality has been added to all textboxes and textboxes within your application will automatically get this ability when run on the updated emulator or a device which has had the update applied. This applies even if you make the textbox readonly.

If you are using a textbox within a Pivot or Panorama (which the guidelines advise against) you should review your app with regard to any possible problems in this area. (Sliding with a finger to expand the selected area may cause the pivot or panorama to slide. You probably don't want this.)

Mango Update

Mango (v7.1) introduces programmatic access to the Clipboard but only for setting text, not getting any text which is already there.

From MSDN:

"You cannot get clipboard text from a Windows Phone application, only set it. Calling the GetText method in a Windows Phone application will always cause a SecurityException to occur."

Matt Lacey
  • 65,560
  • 11
  • 91
  • 143
  • 1
    So the guidelines advise against a TextBox in the pivot, but if you compile against the new dev tools then apparently they contain a fix for the scenario: "Fixes a text selection bug in pivot and panorama controls. In applications that have pivot or panorama controls that contain text boxes, users can unintentionally change panes when trying to copy text. To prevent this problem, open your application, recompile it, and then resubmit it to the Windows Phone Marketplace." Source: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=49B9D0C5-6597-4313-912A-F0CCA9C7D277 – dwynne Feb 05 '11 at 14:16