Search code examples
c#uwpwin-universal-appwindows-10-universal

Stop screen capture on UWP app in TaskView of Windows 10


I stop screen capturing on my UWP app by

ApplicationView.GetForCurrentView().IsScreenCaptureEnabled = false;

However, the app still shows its preview on Taskview of Windows 10 enter image description here

Can someone let me know how to disable the app's preview on Task view

This is the current TaskView enter image description here

and this is how I need it enter image description here


Solution

  • Capturing an app's thumbnail looks like a system behavior, and I don't know how to disable it.

    But since the capture only happens when the user presses Alt+Tab or clicks the task switch button on the task bar, there is a chance to cover the app with an overlay before system takes a screen capture of the app.

    First add an opaque overlay, and set its initial visibility as Collapsed.

    <Grid>
        <TextBlock FontSize="50" Text="Your controls here!" />
        <Grid Background="Black" x:Name="overlay" Visibility="Collapsed" />
    </Grid>
    

    Then register a handler for app window's Activated event,

    Window.Current.Activated += Current_Activated;
    

    Display/Hide the overlay when window is deactivated/activated,

    private void Current_Activated(object sender, Windows.UI.Core.WindowActivatedEventArgs e)
    {
        if (e.WindowActivationState == Windows.UI.Core.CoreWindowActivationState.Deactivated)
        {
            overlay.Visibility = Visibility.Visible;
        }
        else
        {
            overlay.Visibility = Visibility.Collapsed;
        }
    }