Windows Phone 8 APP中禁用截图
---
date: Oct 15, 2014
tags:
-
C#-
WP8-
WP8.1
---
Windows Phone 8 有系统自带的截图功能,快捷键:电源键+Win键,可以随意截图。
Windows Phone 更新GDR2后新增了一个隐藏功能,允许APP禁用截图功能。
PhoneApplicationPage.IsScreenCaptureEnabled
这个隐藏的属性需要通过反射来访问和修改状态。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| public static class PhoneApplicationPageExtensionMethods { public static bool CanSetScreenCaptureEnabled(this PhoneApplicationPage page) { return Environment.OSVersion.Version >= new Version(8, 0, 10322); } public static void SetScreenCaptureEnabled(this PhoneApplicationPage page, bool enabled) { var propertyInfo = typeof(PhoneApplicationPage).GetProperty("IsScreenCaptureEnabled"); if (propertyInfo == null) { throw new NotSupportedException("Not supported in this Windows Phone version!"); } propertyInfo.SetValue(page, enabled); } public static bool GetScreenCaptureEnabled(this PhoneApplicationPage page) { var propertyInfo = typeof(PhoneApplicationPage).GetProperty("IsScreenCaptureEnabled"); if (propertyInfo == null) { throw new NotSupportedException("Not supported in this Windows Phone version!"); } return (bool)propertyInfo.GetValue(page); } } }
|
调用CanSetScreenCaptureEnabled()
方法检测Windows Phone版本是否符合要求(version 8.0.10322以上)。符合条件,然后就通过扩展方法GetScreenCaptureEnabled()
和SetScreenCaptureEnabled()
来修改PhoneApplicationPage.IsScreenCaptureEnabled
属性。
使用:
1 2 3 4 5 6 7 8 9
| public MainPage() { InitializeComponent(); if (this.CanSetScreenCaptureEnabled()) { this.SetScreenCaptureEnabled(false); } }
|

Navigation