Adding share (Windows Store apps using C#/VB/C++ and XAML)
[This topic is featured in Develop great apps for Windows 8.]
Users often come across information they’re excited to share with someone or use in another app. Share provides a lightweight, in context, easy experience to accomplish. The Share charm is also universally accessible—users can always access it with just a single swipe to share content from your app. Users can also share to another user’s device using Tap and send in the Devices charm.
An app can support the Share feature in two ways. First, it can be a source app that provides content that the user wants to share. Second, the app can be a target app that the user selects as the destination for shared content. An app can also be both a source app and a target app. If you want your app to share content as a source app, you need to decide what data formats your app can provide. We recommend that you try to support as many data formats as possible, but in the end you should choose the ones that make the most sense for your app. After you've made that decision, you use the classes from the Windows.ApplicationModel.DataTransfer namespace to package up the data. If your app shares a file or a URL, your app can also share through Tap and send in the Devices charm.
If you want your app to receive shared content as a target app, you need to first configure your app's manifest file to indicate that it supports the Share Target contract. This contract lets Windows present your app as an option when the user invokes the Share charm in scenarios where supported data formats are shared. When choosing data formats for your target app to support, you should only register for only the formats that your app can handle. For more guidance, please see Choosing data formats. When the user invokes the Share charm, Windows automatically shows only the target apps that support the data being shared.
If you're using Visual Studio, you can add the Share Target contract to your app by choosing Add New Item from the Project menu, and then selecting Share Target Contract from the list. As part of this process, you need to specify the list of data formats and file types your app can accept. You specify the formats in the Declarations tab while editing the package.appxmanifest file in Visual Studio.
To see an example of how to share content, check out our Sharing content source app sample and Sharing content target app sample, or read through our Quickstart: Sharing content and QuickStart: Receiving shared content topics.
Take a look at the following diagram. It shows, at a high level, how sharing works.
If you are implementing a target app, there are a couple of things you should consider. First, when the user selects your app, Windows will display it using the Share flyout. This view state is one of several ways that an app can be displayed on the screen. Make sure your app presents a clean, uncluttered interface for sharing content in the Share flyout.
You can specify a specific form that opens when the app is activated through the Share charm. That way, you can create a customized experience specifically for sharing. You can find more information about this and other design considerations in Guidelines and checklist for sharing content.
When your app receives content from a source app, that content is immutable—you can't change it. You can, however, let the system know that you've received the data and indicate when it's been processed. This is important—especially for content such as pictures, which might take a while to process and upload. Our Sharing content target app sample shows how this works, or you can check out our QuickStart: Receiving shared content for more details.
Keep in mind that while these roles—source and target—are different, you can support both within a single app if you want. For example, a photo sharing app might want to act as a source app so users can email their photos to others, and also act as a target app so users can update photo albums with new pictures.
To get started adding share to your app, check out the following topics and sample apps:
- Guidelines and checklist for sharing content. Whether you're writing a source or a target app, this topic provides some useful information that can help you provide the best user experience possible for sharing content.
- Choosing data formats for sharing. Learn about the standard formats for share, and how to create and use custom formats when the standard formats don't apply.
- Sharing content. Here you'll learn the basics of how to implement a source app. We also cover more specific scenarios and provide a few details you should consider during implementation.
- Receiving shared content. The topics here describe how to add the Share contract to your app, the basics of how to detect if a user selects your app to share content with, and how to process the data being shared. We also describe a few specific scenarios to help you get up and running quickly.
- Sharing content source app sample. This sample shows how to initiate a share operation and package content for sharing.
- Sharing content target app sample. This sample shows how to receive content shared from another app.
- Guidelines for debugging target apps. Learn about the issues involved in debugging a share target app.
Build date: 11/29/2012