not all application windows show after leaving and returning with ALT/TAB

Henriette van de Haar

When my application shows the main window plus on top of that a smaller modal window (which was opened with ShowDialog) I have a problem with ALT/TAB. When I go to another application with ALT/TAB and then return to my application, only the modal window shows, the main window has disappeared. It is only an optical thing. There is no functional problem. The main window has ShowInTaskbar="False" because I do no wish the user to be able to bring to front the inactive main window with ALT/TAB. Does anybody know a solution to this problem?

taquion

I have made this very simple sample:

In your MainWindow.xaml

<Window x:Class="SampleDialog.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Button Content="Show Dialog" Click="ButtonBase_OnClick"></Button>
    </Grid>
</Window>

In codebehind

public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            new Dialog(this).ShowDialog();
        }
    }

In Dialog.xaml

<Window x:Class="SampleDialog.Dialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Dialog" Height="300" Width="300" 
        Activated="Dialog_OnActivated" Deactivated="Dialog_OnDeactivated">
    <Grid>

    </Grid>
</Window>

And in Dialog codebehind

public partial class Dialog : Window
{
    public Dialog()
    {
        InitializeComponent();
    }

    public Dialog(MainWindow main)
        : this()
    {
        _main = main;
    }

    private void Dialog_OnActivated(object sender, EventArgs e)
    {
        Topmost = _main.Topmost = true;
    }

    private void Dialog_OnDeactivated(object sender, EventArgs e)
    {
        Topmost = _main.Topmost = false;
    }

    private readonly MainWindow _main;

The intention is to handle this functionality in Activated and Deactivated events on your modal window.

Hope it helps.

(If you are using MVVM then you must refactor to handle this on a WindowService class or by using EventToCommand approach)

EDIT>>> This works for your case when ShowInTaskbar = "False". =)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to show (raise) all windows of an application?

After leaving and returning to Activity, Listview shows multiples of items

How to show a window on top of all windows of the same application

Android: AsyncTask needs a context to show an alert after leaving containing activity

show last updated activity after leaving current activity in android

Get back to mobile application after leaving it with Appcelerator Titanium

Webview does not close after leaving the page in Xamarin.Forms Application

Application windows all move to main display after screens turn back on

Returning all desktop windows with PyWinAuto

R Returning all characters after the first underscore

Show all open windows in 11.04?

When loggin in after inactivity all windows be in minimized state (show desktop wallpaper)

Elm form - show validation error only after leaving the field and no input was entered - dirty/visited

Capturing all windows messages to an application

Windows application closes after printing

Console application does not show after upgrading TFM

Trying to use windows batch to remove all extra spaces while leaving exactly one space between values

Windows User Folders Called Username.Hostname After Leaving ActiveDirectory Domain/Demoting Server from AD Controller

Open URL without leaving application

Not All Notifications Show after being Offline

How to reset/show all elements after hidden

Show all errors after click submit

Are there events which show application launches and activity in Windows?

Remove delay after leaving the hover

Values vanishing after leaving function

React Interval not stopping after Leaving

carousel leaving pixels after moving

Data reset after leaving a constructor

Jersey restful web application returning 404 for all resource URI's