Disabling screenshot functionality in a Windows Phone app

Update: Kudos to Murat and Rudy Huyn for pointing me out on a missing return; that would cause the NotSupportedException to be raised all the time… I’ve fixed the code by inverting the if condition.

Update 2: Just noticed that GDR2 is also supported, as the code below will also work in devices with it! :)

Windows Phone 8 made it possible to take a screenshot of your screen at any time, just by pressing the Windows and Power button at the same time.

Sure, this is a really cool feature and can be quite handy from time to time, but it can become a security concern for some specific scenarios, not to mention a way to copy someone else’s graphical designs!

Since Windows Phone 8 update 3 (GDR2) there is now a hidden feature that allows you to disable the Screenshot functionality on a page by page basis: the PhoneApplicationPage.IsScreenCaptureEnabled!

This is a hidden property that requires Reflection in order to access and modify it’s state. The following extension methods will help you with that:

publicstaticclassPhoneApplicationPageExtensionMethods{publicstaticboolCanSetScreenCaptureEnabled(thisPhoneApplicationPagepage){returnEnvironment.OSVersion.Version>=newVersion(8,0,10322);}publicstaticvoidSetScreenCaptureEnabled(thisPhoneApplicationPagepage,boolenabled){varpropertyInfo=typeof(PhoneApplicationPage).GetProperty("IsScreenCaptureEnabled");if(propertyInfo==null){thrownewNotSupportedException("Not supported in this Windows Phone version!");}propertyInfo.SetValue(page,enabled);}publicstaticboolGetScreenCaptureEnabled(thisPhoneApplicationPagepage){varpropertyInfo=typeof(PhoneApplicationPage).GetProperty("IsScreenCaptureEnabled");if(propertyInfo==null){thrownewNotSupportedException("Not supported in this Windows Phone version!");}return(bool)propertyInfo.GetValue(page);}}

The first step is to call CanSetScreenCaptureEnabled() from inside your PhoneApplicationPage to check if the Windows Phone version is at least Windows Phone 8 update 3 (version 8.0.10322) as that is the minimum required version for this to work!

If it is, we can then use the GetScreenCaptureEnabled() and SetScreenCaptureEnabled() extension methods to change the property value!