I also had this problem recently. The general user interface crashes when one of the important parameters is not set. In your case, I suspect that
this.article.UrlDomain
is a null or invalid Uri pattern. You must create an if statement around it and make sure you are dealing with a real Uri. To test your code, you need to insert hard-coded constants and run it again. If it does not crash, check your Title , Summary and UrlDomain in turn.
Other places to explore:
Try adding a handler to the OnNavigatedTo method and delete it when you leave the page
protected override async void OnNavigatedTo(NavigationEventArgs e) { DataTransferManager.GetForCurrentView().DataRequested += SharePage_DataRequested; } protected override void OnNavigatingFrom(NavigatingCancelEventArgs e) { base.OnNavigatingFrom(e); DataTransferManager.GetForCurrentView().DataRequested -= SharePage_DataRequested; }
I also looked for my code and looked at the official samples again and did not find any doffers. Just to be sure - if I were you, I would separate all the unprotected lines in my code and bring it as close as possible to the official examples, and then continue it back to where it was from there, so I would comment on these two lines:
void SharePage_DataRequested(DataTransferManager sender, DataRequestedEventArgs args) { DataRequest request = e.Request; //DataRequestDeferral defferal = request.GetDeferral(); request.Data.Properties.Title = this.article.Title; request.Data.Properties.Description = this.article.Summary; request.Data.SetWebLink(new Uri(this.article.UrlDomain)); //defferal.Complete(); }
source share