Categories
Windows Phone

Clipboard API for Windows Phone 8.1

In the latest release of Charming Share which is now live on NuGet I’ve added a new Clipboard API.

For Windows Phone 8 and 8.1 Silverlight apps this wraps the existing Silverlight functionality. For Windows Phone Store 8.1 applications this provides a workaround to the lack of any Clipboard API on that platform. The library provides a Windows-style API (differing only in root namespace) to make it easier to share more code across projects.

As with the existing Silverlight model the Clipboard is “write-only” with only the user in control of pasting the contents into a TextBox. It exposes two static methods – SetContent and Clear. I haven’t yet updated the documentation on the project site but these two methods are fairly straight-forward. Unlike “big” Windows the clipboard can only store plain text (again this is familiar from the Silverlight model) so will accept data packages containing text or Uris.

In order to facilitate this functionality on non-Silverlight apps on 8.1 there is of course a gotcha. It requires a separate app to be installed and there is a small visual transition while this app handles the request. This isn’t ideal but if there are some cases where you need Clipboard it is a necessary evil and by matching the Windows Store API we have hopefully provided a clean transition should this missing feature be added in a future release.

Why would I want another app? When building this solution I though about how this add-on app could provide additional value and so it takes advantage of a number of Windows Phone 8.1 features. It doesn’t use any online services so the data you share with it never leaves the device. It’s a simple free app called “Clipboarder” and I encourage you to check it out (and provide feedback!).

Share Target: You can share text and Uris to the clipboard from other Windows Phone 8.1 apps which are Share sources.

Share Source: If you run the app from the programs list you can enter arbitrary text and either copy to the clipboard or Share with other Windows Phone 8.1 targets.

Download from the Windows Phone Store

By Peter Foot

Microsoft Windows Development MVP

2 replies on “Clipboard API for Windows Phone 8.1”

var data = new DataPackage();
data.SetText(“what”);
Clipboard.SetContent(data);

and then the windows phone 8.1 will alter you like this “Search for app in the store…”

That is correct – the only way to provide the functionality for Windows Phone 8.1 apps is via a separate app. On Windows Phone Silverlight (8.0 and 8.1) the API works directly with the clipboard.

Comments are closed.