How to use ShareLinkTask namespace in Windows Phone 8.1?

左心房为你撑大大i 提交于 2020-01-21 03:47:07

问题


I am developing an app and i am trying to share my app, in Windows Phone 8 Siverlight and Windows Phone 8.1 Silverlight, i used these codes:

ShareLinkTask shareLinkTask = new ShareLinkTask();

        shareLinkTask.Title = "Code Samples";
        shareLinkTask.LinkUri = new Uri("http://code.msdn.com/wpapps", UriKind.Absolute);
        shareLinkTask.Message = "Here are some great code samples for Windows Phone.";

        shareLinkTask.Show()

But in Windows Phone 8.1 using Windows Runtime, when i use these codes, it reports an error that this namespace doesn't exist. So, what namespace can replace ShareLinkTask on Windows Phone 8.1 using Windows Runtime ? Sorry for my bad english. Thank you !


回答1:


In Windows Phone 8.1, You can share link using DataTransferManager(namespace:Windows.ApplicationModel.DataTransfer).

Here is code:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    DataTransferManager dtManager = DataTransferManager.GetForCurrentView();
    dtManager.DataRequested += dtManager_DataRequested;
}

private async void dtManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
{
    e.Request.Data.Properties.Title = "Code Samples";
    e.Request.Data.Properties.Description = "Here are some great code samples for Windows Phone.";
    e.Request.Data.SetWebLink(new Uri("http://code.msdn.com/wpapps"));
}
// Click Button to share Web Link
private void btnShareLink_Click(object sender, RoutedEventArgs e)
{
    Windows.ApplicationModel.DataTransfer.DataTransferManager.ShowShareUI();
}


来源:https://stackoverflow.com/questions/24924949/how-to-use-sharelinktask-namespace-in-windows-phone-8-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!