Windows Phone APP中禁用截图

Windows Phone 8 有系统自带的截图功能,快捷键:电源键+Win键,可以随意截图。

Windows Phone 更新GDR2后新增了一个隐藏功能,允许APP禁用截图功能。

PhoneApplicationPage.IsScreenCaptureEnabled

 这个隐藏的属性需要通过反射来访问和修改状态。

 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属性。
使用:

      // 构造函数
        public MainPage()
        {
            InitializeComponent();

            if (this.CanSetScreenCaptureEnabled())
            {
                this.SetScreenCaptureEnabled(false);
            }
        }

目前在真机(系统为WP8,WP8.1上效果如何不懂)上测试有效,没弄懂模拟器如何像真机一样截图,所以模拟器上没成。

效果如下图

 

以后就有些东西不能截图了( ╯□╰ )

 对了,需要看原文的戳:Disabling screenshot functionality in a Windows Phone app  。

转载于:https://www.cnblogs.com/shiyix/p/3656195.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值