Skip to content

Instantly share code, notes, and snippets.

@igorkulman
Last active August 29, 2015 14:00
Show Gist options
  • Save igorkulman/11111043 to your computer and use it in GitHub Desktop.
Save igorkulman/11111043 to your computer and use it in GitHub Desktop.
AssociationUriMapper settings for being a share contract target in Windows Phone 8.1 Silverlight app
public class AssociationUriMapper : UriMapperBase
{
public override Uri MapUri([NotNull] Uri uri)
{
var op = (Application.Current as App).ShareOperation;
if (op != null)
{
var link = op.Data.GetWebLinkAsync().GetResults();
return new Uri("/Views/AddedView.xaml?Uri=" + HttpUtility.UrlEncode(link.ToString()), UriKind.Relative);
// Otherwise perform normal launch.
return uri;
}
}
protected override void OnLaunch(object sender, Microsoft.Phone.Shell.LaunchingEventArgs e)
{
base.OnLaunch(sender, e);
var shareTargetLaunch = e as ShareLaunchingEventArgs;
if (shareTargetLaunch != null)
{
(App.Current as App).ShareOperation = shareTargetLaunch.ShareTargetActivatedEventArgs.ShareOperation;
}
}
protected override PhoneApplicationFrame CreatePhoneApplicationFrame()
{
var frame = new PhoneApplicationFrame();
frame.UriMapper = new AssociationUriMapper();
return frame;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment