简体   繁体   中英

How to add Share button to the CommandBar of a Windows 10 Mobile UWP App and sharing capabilities to it?

  1. I'm trying to add a button to the command bar of a phone app (8.1 and UWP) with a typical Windows Phone share icon. How do I add such an icon to it?

  2. I'd also like it to bring up the sharing window where the user can select the different ways of sharing something. It would share the link to my app in the store, like from the store app.

1: There is no share charm in Windows 10. What you can do is that you do the icon yourself. This would make it:

<AppBarButton Label="Share"  >
    <AppBarButton.Icon>
        <FontIcon FontFamily="Segoe MDL2 Assets" Glyph="&#xE72D;"/>
    </AppBarButton.Icon>
</AppBarButton>

2:

In UWP I would use Share contract. (Basically the DataTransferManager class…)

Here is a good documentation for that: https://msdn.microsoft.com/en-us/library/windows/apps/xaml/mt243293.aspx

Basically:

Hook up the event (eg in your page's constructor..):

DataTransferManager.GetForCurrentView().DataRequested += MainPage_DataRequested;

Show the UWP share UI (eg on the button's event handler..)

DataTransferManager.ShowShareUI();

Do the sharing:

private void MainPage_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
       args.Request.Data.SetWebLink(URI); 
       args.Request.Data.Properties.Title = "My new title";
       args.Request.Data.Properties.Description = "description";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM