Here are the steps:
Step 1: Open a blank app and add a Button and a TextBlock either from the toolbox or by copying the following XAML code into your grid.
- <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
- <Button x:Name="captureButton" Content="Enable Capture" Click="captureButton_Click" />
- <TextBlock Name="status" Margin="0,10,0,0"></TextBlock>
- </StackPanel>
Step 2:
Copy and paste the following code to the cs page which will be called on button click event and will control the ScreenCapture and will show the status also:
- 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;
- }
- }
When the ScreenCapture is disabled you will only get a black screen while trying to capture the same using any tool.
Step 3: Run your application and test yourself.