windows - 如何将共享按钮添加到 Windows 10 移动 UWP 应用程序的命令栏并向其共享功能?

标签 windows uwp windows-phone share

  1. 我正在尝试向带有典型 Windows Phone 共享图标的电话应用程序(8.1 和 UWP)的命令栏添加一个按钮。我如何向它添加这样的图标?

  2. 我还希望它能调出共享窗口,用户可以在其中选择不同的共享方式。它会在商店中共享指向我的应用程序的链接,就像从商店应用程序中一样。

最佳答案

1:Windows 10没有分享魅力,只能自己做图标了。这将使它:

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

2:

在 UWP 中,我会使用共享契约(Contract)。 (基本上是 DataTransferManager 类……)

这是一个很好的文档: https://msdn.microsoft.com/en-us/library/windows/apps/xaml/mt243293.aspx

基本上:

连接事件(例如在页面的构造函数中......):

DataTransferManager.GetForCurrentView().DataRequested += MainPage_DataRequested;

显示 UWP 共享 UI(例如,在按钮的事件处理程序上......)

DataTransferManager.ShowShareUI();

做分享:

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";
}

关于windows - 如何将共享按钮添加到 Windows 10 移动 UWP 应用程序的命令栏并向其共享功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33265938/

相关文章:

c# - RestSharp 无效的 URI : The URI Scheme is not valid

windows - 从 PowerShell 启动 WinRT 应用程序

php - 如何在 Windows 上为 PHP 安装 PDO 驱动程序?

python - 在 cygwin 中列出文件内容时遇到问题

c# - 如何在 UWP App 中创建信息提示通知

c# - 异常 HRESULT : 0x800455BC in speech recognition in Windows phone 8

Windows Dir 命令 - 按大小排序子目录

c# - UWP GridView 图像拉伸(stretch)错误

c# - GZIPStream 压缩总是返回 10 个字节

windows-phone - 如何在 Windows Phone Toolkit 中创建过渡动画?