When building a WinRT/Metro application one of the key integration points between your application and others is to allow Data Sharing via the Sharing Contracts. By default applications DO NOT support sharing and when a user taps on the Share Charm they will see an error similar to the following.
This message is NOT that user friendly and should be avoided. Besides what good does a screenshot of your application really do anyone .
If you are explicitly not going to support sharing from a given view in your application you should provide the user a little better message telling them this, fortunately setting this up is a piece of cake.
To setup this clean user friendly message we simply need to do 3 things
- Grab the DataTransfer Context for the current view
Add the following using clause : using Windows.ApplicationModel.DataTransfer
Grab the context as : var dtm = DataTransferManager.GetForCurrentView();
- Setup the event to handle the DataRequested event
Wire up the DataRequested event as: dtm.DataRequested += OnDataRequested;
- Populate the failure message in the Share Panel with our user friendly message
Inside your event handler do the following:
args.Request.FailWithDisplayText( "Data Sharing Not Supported at this time" );
The args object is of course the EventArgs which is passed into your event handler.
One thing to pay attention to is that the amount of text which can be displayed is very short. If you provide a value which is too long the value will be truncated and the … will be appended to the end.
Now that we have enabled our view to display a friendly error message when someone tries to invoke the share we should see something like the following;
(please not the … added to the message. This is what I was referring to above when I said it will truncate long messages)
Till next time,
10-09-2011 6:54 AM