Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 985
robcsi Avatar asked Oct 21 '15 17:10

robcsi


People also ask

Which button appear on the command bar?

The command bar can be open or closed. When it's open, it shows primary command buttons with text labels and it opens the overflow menu (if there are secondary commands). The command bar opens the overflow menu upwards (above the primary commands) or downwards (below the primary commands).

How do I change the icon on my UWP app?

Set "Run" to "minimized" and pin it to the taskbar. You probably also want to change the icon (btw you can get the . ico icon of a website by copying it from a Chrome website-shortcut). Then set "Run" to "minimized", add your custom icon and pin it to the taskbar.

How do I run UWP apps on Windows 7?

With this tie-in, when using Uno Platform to get your UWP/WinUI 3.0 and later apps on Windows 7 you now have two options for running your app: Run your app as a PWA. Your Windows 7 will need Chrome installed on it. Run your app on Chromium through Electron.


1 Answers

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 (e.g. in your page’s constructor..):

DataTransferManager.GetForCurrentView().DataRequested += MainPage_DataRequested;

Show the UWP share UI (e.g. 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";
}
like image 117
gregkalapos Avatar answered Oct 18 '22 21:10

gregkalapos