Quickly build Windows 8 style apps 15-sharecontract Build

Source: Internet
Author: User

Original: Build Windows 8 style app 15-sharecontract quickly

This blog post focuses on shared data packages, how to build shared feeds, how to build shared targets, and Datatransfermanager classes.

Shared Data Packages

DataPackage (packet) is a shared data standard.

The shared data format can be multiple, including text, URIs, HTML, images, and more, as well as more extensible formats.

We can set the required sharing data type in the following ways:

1) SetText (): Set shared text, for example:

Results can be achieved:

2) Seturi (): Set the shared URI;

3) Sethtmlformat (): Set shared HTML;

4) SetBitmap (): Set the shared bitmap, for example:

Results can be achieved:

5) Setrtf (): Set shared Rich text;

6) SetData (): Set up shared data;

7) Setstorageitems (): Set up shared files or folders;

The sample code for using these methods is as follows:

Example code address: http://code.msdn.microsoft.com/windowsapps/Sharing-Content-Source-App-d9bffd84

How to build a shared source

What is the first thing to consider as a shared source application?

1) Listen and handle the shared events to be involved;

2) content can be shared in two ways: implicit [user selects "Share" without selecting content] and displays [user selects "Share" after selecting content in the app];

3) Build the data package to get the best results;

So how do you build a shared source in your own application?

The first step:

You need to register the datarequested event for the Datatransfermanager class in the page code where you want to share the data, which is triggered when the user delimits the charms (the charms) and chooses to share (Share contract).

Step Two:

In the ondatarequested function, write the packets that the application will share.

The code first needs to pass args. The request gets to the current form requesting the shared object, and then sets the related properties of the data class of the request object to share the text, picture, and other information. Where Data.Properties.Thumbnail can set the thumbnail of the packet.

With the above steps, we can share the data and see the packet information to be shared in the Share panel. Effect

Step Three:

After sharing is complete, we need to log off the Datarequested event on the current action page to avoid consuming more resources from the system.

How to build a shared target

In general, applications such as social, instant messaging, cloud storage, and print device classes are used as shared target applications. If our application accepts shared data from other applications, then our application becomes a shared target program.

The application becomes a shared goal, which increases the usage of the app or service and enables the service to have the most up-to-date content relevant to the user.

What do I need to consider as a shared target app?

1) Register as a shared target and specify the accepted format;

2) Build a shared user interface that makes it part of the shared experience, including: [People or Location selection shared in the app] and [fast lightweight experience];

3) Use Datapackage to extract the data that is most suitable for sharing;

4) After the sharing is done, it is best to prompt the user to share the success, and the user should be able to realize sharing progress or cancel the shared operation during the sharing process;

5) return a QuickLink (quick link), e.g. where to share;

So how do we build shared goals?

The first step:

Open the app manifest file for our application, declare the application as share Target, and set the data format to accept the packet.

Step Two:

The Onsharetargetactivated method is overridden in the App.xaml.cs file to receive requests for system calls.

In the Onsharetargetactivated method, when the app is activated as a shared target, navigate to the Application Share destination page (the example navigates to the MainPage page).

Step Three:

The Shared destination page resolves the shared packet information.

The code begins with the E. parameter is cast to the Shareoperation class, and then through the Shareoperation object you can get information about the properties of the packet, including the text, the Uri, the picture, and other formats.

back to QuickLink :

Just now we mentioned that after getting the package data and processing, you can return the system a QuickLink, the code can be as follows:

Once the QuickLink is successfully returned, our app will appear as a common target in the sharing panel.

Our target application can also use Shareoperation.quicklinkid to determine whether or not to enter the target application from QuickLink in the method of acquiring the packet data, and to do special processing according to different quicklinkid.

Datatransfermanager class

The Datatransfermanager class plays a very important role in implementing share contract, so what are the important methods and events involved?

1) datarequested event: Triggered at the start of a shared operation;

2) Targetapplicationchosen event: triggered when the target application is selected;

3) Getforcurrentview method: Get the Datatransfermanager related to the current form;

4) Showshareui method: Display the sharing panel;

Quickly build Windows 8 style apps 15-sharecontract Build

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.