Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide app preview from Alt-tab taskbar in Windows 10 Universal App Platform

I'm developing an app and I'd like when the user is in Tablet Mode and switches from one app to other to show a black screen when you press "alt + tab" and the opened apps are being shown. I'd like instead of showing the "myTrip" screenshot of the app to show a black screen.

enter image description here

I know for WPF we had ShowInTaskbar = false but nothing like that in Windows 10 Universal App Platform.

I tried so far:

Window.Current.CoreWindow.VisibilityChanged += CoreWindow_VisibilityChanged;

  private void Current_VisibilityChanged(object sender, VisibilityChangedEventArgs e)
    {
        var parentGrid = RootPanel();
        parentGrid.Visibility = e.Visible ? Visibility.Visible : Visibility.Collapsed;
    }

But the snapshot image of the app is taken before those events are being called. Any idea on how to do it?

Regards.

like image 982
Fritjof Berggren Avatar asked Apr 25 '16 14:04

Fritjof Berggren


1 Answers

I don't get why exactly you want to do this, but here it goes.

You'll need to handle the Activated event of the current thread, and than place a control over your content. See the example bellow.

First, the XAML:

<Canvas Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" >
    <Canvas x:Name="contetProtector" Canvas.ZIndex="10" Background="Black" Width="1014" Height="758" Visibility="Collapsed"/>
    <TextBlock Text="My precious content" FontSize="50" Canvas.Top="50" Canvas.Left="50"/>
    <TextBlock Text="Nobody should see it" FontSize="50" Canvas.Top="100" Canvas.Left="50"/>
</Canvas>

Then, the codebehind of the page:

public MainPage()
{
    this.InitializeComponent();
    CoreWindow.GetForCurrentThread().Activated += CoreWindowOnActivated;
}

private void CoreWindowOnActivated(CoreWindow sender, WindowActivatedEventArgs args)
{
    if(args.WindowActivationState == CoreWindowActivationState.Deactivated)            
        this.contetProtector.Visibility = Visibility.Visible;
    else
        this.contetProtector.Visibility = Visibility.Collapsed;
}

Here you can see the unprotected/active screen, and here the protected one.

Hope it helps.

like image 147
Iuri Farenzena Avatar answered Oct 06 '22 01:10

Iuri Farenzena