Blog Park client UAP Development essays – Connect your app to the World (2): Built-in sharing in WINRT

Source: Internet
Author: User

See a bright blog post, is there a hope that other small partners can see the feeling? Is there a "no-go-no-programmer" impulse? See on the PC browser is OK, the direct URL copy, the other side of the IM on the past, but if it is the content of the App, it is not so convenient, always can not over there on the IM: "Next door Lao Wang, blog Park has an article called ' Blog Park Client (Universal app) development essay-for application plug-in sharing The Wings ' blog is super-nice, or you can also look at? ”。 It would be too much trouble to search the old king next door. Maybe you'll say, hey, just share it. Well, yes, that's the sharing feature. So how do we bring the sharing function into our App? Look down.

The similarities and differences between windows/windows phones in the Universal App

Since it's the Universal App, it's natural to share a shared set of code. But there is something different between the two. The difference is that the Windows edition has a system-level menu of Charm Bar, and the menu comes with a shared portal, so the Windows edition only needs to be prepared in advance for the content to be shared without having to provide another shared portal. Windows Phone does not have this portal, so in addition to the need to prepare the content, but also through the form of a menu or a button to explicitly provide a shared portal.

However, with the release of Windows 10, the life of Charm Bar has come to an end, in the previous Technical preview can occasionally (mistakenly touch) call up Charm Bar, but in just released costumer preview, we should see not To Charm Bar, all the entrances that it provided were moved to the position shown:

This is not difficult to understand, because all the apps can be windowed, the right slide to bring up the Charm Bar method has not been used, so provide a separate entrance. However, the size of the entrance is not very good to click, and the outgoing menu is more prone to accidental contact, especially on Surface Pro's high-split screen. This change, also makes the original up/down call out APP Commands operation needs two steps to complete, extremely cumbersome. As a result, we have to add the quick access to the APP Commands in the new blog park.

In addition, Windows provides two ways to share by default, one is to use the information provided by the developer, and the second is to share the current screen directly. As of today's Windows Phone Technical Preview, there is only one way to share, without the option of screenshots. In Windows Phone, we also need to manually add a portal, as shown in.

Create share (with Text example)

Well, let's take a look at blog post to share some examples of how to create a share.

Before we start, let's think about what we need to share in our minds. For example, Blog Park we need to share information in the following format (within the split line):

--------------

Title: Post Title

Blog author

Summary: Blog Summary

Blog links

--------------

The idea is that we first create a string that contains the above information, and then join the registration to the share, and then explicitly or systematically call out the sharing portal to share.

The specific implementation is as follows:

First add a reference:

using Windows.ApplicationModel.DataTransfer;

Then create a method called Registerforshare to register the content you want to share with the sharing area:

Private void Registerforshare ()        {            = datatransfermanager.getforcurrentview ();             New Typedeventhandler<datatransfermanager, datarequestedeventargs> (this. Sharetexthandler);        }

In this method, we create a datatransfermanager and let him start at the Datarequested event Sharetexthandler method:

Private voidSharetexthandler (datatransfermanager sender, Datarequestedeventargs e) {datarequest request 
    =e.request; Request. Data.Properties.Title= Loader. GetString ("Sharetitleprefixtext") + This. Post.                Title; Request. Data.Properties.Description= This. Post.                Summary; stringSummarytext = ( This. Post. Author! =NULL? Loader. GetString ("Sharecontentauthor") + This. Post. Author.name:"") +"\ n"+ Loader. GetString ("sharecontentsummary")                                   + ( This. Post. Summary.length > -? This. Post. Summary.substring (0, -) : This. Post. Summary) +"\ n"+ This. Post.            Link.href; Request.        Data.settext (Summarytext); }

Next implement this method, create a request, and refine the content therein, where request. Data.Properties.Title is the content that will be displayed in the title section of the share, for example, if it is a mail share, then the message header is request. Data.Properties.Title, if Onenote shares, then Note's title will also be request. Data.Properties.Title. Request. Data.Properties.Description is not a required option, it's just a note reference and won't show up when you share it. The last request. Data.settext (Summarytext); Set up the rest of the content you need to share. In this way, the content we need to share is already filled in like we thought before.

The next thing to do is to call the Registerforshare method first, which can be done in the constructor.

Share Portal

In the case of Windows, after the constructor has called the Registerforshare method, it can already be shared directly, and the entry is the Charm Bar or menu previously mentioned:

The drop-down menu on the right lets you choose to share content or screenshots:

We choose email to share content

You can send it.

If it's a Windows Phone, then we need to do one more step.

To create a menu entry:

<x:name= "Btn_share"  x:uid= "Shareblogbutton"  Label  = "Share Blog"  Click= "Btn_share_click"  Icon= "Reshare"/> 

Then, in the click Method, explicitly call the sharing Portal:

Private void Btn_share_click (object  sender, RoutedEventArgs e)        {            Windows.ApplicationModel.DataTransfer.DataTransferManager.ShowShareUI ();        }

This will bring up the sharing portal of the system:

Because it is a simulator test, there is no MS account, so there is no email sharing portal.

We choose SMS

You can send the share content.

Other sharing formats

In addition to SetText to share content in text format, we can also create content such as Html,weblink and files. Concrete implementation and Text is similar to the implementation of details, you can refer to:

Text:https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh871372.aspx

Weblink:https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh973056.aspx

Html:https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh973055.aspx

Files:https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh871371.aspx

Summarize

Through the above introduction, we can use a few code to achieve the content we like to quickly share the purpose of others. We no longer have to worry about the next-door old king not seeing the points we gave them (SAO).

share the code and change the world!

Windows Phone Store App Link:

http://www.windowsphone.com/zh-cn/store/app/Blog Park-UAP/500F08F0-5BE8-4723-AFF9-A397BEEE52FC

Windows Store App Link:

http://apps.microsoft.com/windows/zh-cn/app/c76b99a0-9abd-4a4e-86f0-b29bfcc51059

GitHub Open Source Link:

Https://github.com/MS-UAP/cnblogs-UAP

MSDN Sample Code:

Https://code.msdn.microsoft.com/CNBlogs-Client-Universal-477943ab

Blog Park client UAP Development essays – Connect your app to the World (2): Built-in sharing in WINRT

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.