[英]How to add Share button to the CommandBar of a Windows 10 Mobile UWP App and sharing capabilities to it?
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. 我正在尝试使用典型的Windows Phone共享图标向手机应用程序(8.1和UWP)的命令栏添加一个按钮。 How do I add such an icon to it?
如何添加这样的图标?
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. 1:Windows 10中没有共享魅力。您可以做的是自己做图标。 This would make it:
这将使它:
<AppBarButton Label="Share" >
<AppBarButton.Icon>
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph=""/>
</AppBarButton.Icon>
</AppBarButton>
2: 2:
In UWP I would use Share contract. 在UWP中,我会使用股份合约。 (Basically the DataTransferManager class…)
(基本上是DataTransferManager类......)
Here is a good documentation for that: https://msdn.microsoft.com/en-us/library/windows/apps/xaml/mt243293.aspx 这是一个很好的文档: 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..) 显示UWP共享UI(例如,在按钮的事件处理程序上..)
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";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.