Derik Whittaker

Syndication

News


How to setup a clean error message when your Metro Application does not support Data Sharing

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.

image

This message is NOT that user friendly and should be avoided.  Besides what good does a screenshot of your application really do anyone Smile.

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

  1. 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();

  1. Setup the event to handle the DataRequested event

Wire up the DataRequested event as: dtm.DataRequested += OnDataRequested;

  1. 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;

image 

(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,


Posted 10-09-2011 6:54 AM by Derik Whittaker
Filed under: , , ,

[Advertisement]

Comments

Stephen Taylor wrote re: How to setup a clean error message when your Metro Application does not support Data Sharing
on 10-09-2011 11:02 AM

Please don't do this, this is horrible- not only do you ironically make the message less user friendly, but you disable the OS from giving the user a default sharing option.

Try to remember this isn't about you, its about the user, the reason windows is such a mess in the first place is because developers had to much reign over the OS and would create a clusterf- of terrible experience.

Derik Whittaker wrote re: How to setup a clean error message when your Metro Application does not support Data Sharing
on 10-09-2011 11:19 AM

@Stephen,

Your right this is about the user which is exactly WHY it is their their benefit to know that a given screen was explicitly setup to NOT allow sharing.  By default screens do NOT allow sharing so having a clean message, one other than 'grab a screen print' is  a way better option.

Besides, even if you say this is 'horrible' the option is still there and it is an option that many app developers are going to want to implement so this post shows them HOW to do it

stephane wrote re: How to setup a clean error message when your Metro Application does not support Data Sharing
on 10-10-2011 6:14 PM

Well, I am with Stephen here. You remove the option of sharing something by default (the screenshot).

The real only option here is to actually implement sharing. It is not an optional feature in Metro style applications. It is meant to be part of the experience and by refusing to implement it, you make your app look broken in the user eyes.

Derik Whittaker wrote re: How to setup a clean error message when your Metro Application does not support Data Sharing
on 10-10-2011 6:42 PM

@Stephane,

Last i knew sharing WAS optional and is NOT something you must implement.

If the given view does not have anything worth sharing or for privacy reason you do NOT want to share what else are you supposed to do?  Lets say I leave the default behavior such as sharing screen shots turned on and my metro application is a healthcare application I have not just opened up the possibility for a VERY BIG HIPAA violation.....

Also, this same code can be use to show a user an actual error message <gasp>

Everyone, use your head here.  There are times we want to share and there are times we do not.  Not everything is black and white and sometimes, just sometimes we have to think for ourselves.

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)