UWP基础教程 - 禁用&开启截取应用屏幕

用过iOS支付宝的同学都应该知道,在切换App的时候界面是模糊的,为了防止自己的隐私数据被泄露,本文就是告诉大家如何在UWP应用中实现这个效果么。

新建一个页面,在.xaml里加入下列代码

<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
  <Button x:Name="CaptureButton" Content="Enable Capture" Click="CaptureButton_Click" />
  <TextBlock Name="status" Margin="0,20,0,0"></TextBlock>  
</StackPanel>

在.cs里面加入下面Click事件代码

private void CaptureButton_Click(object sender, RoutedEventArgs e)  {  
    if (captureButton.Content.ToString() == "Enable Capture")  
    {  
        captureButton.Content = "Disable Capture";  
        status.Text = "Screen Capturing is enabled";  
        Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().IsScreenCaptureEnabled = true;  
    }  
    else  
    {  
        captureButton.Content = "Enable Capture";  
        status.Text = "Screen Capturing is disabled";  
        Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().IsScreenCaptureEnabled = false;  
    }  
}

该应用默认是开启截图功能的,截图如下所示

::: hljs-center

:::

如果你关闭了截图功能,当你使用截图软件的时候,你会发现截取的是一个黑色的屏幕界面。

::: hljs-center

:::

Comment