[英]Show a list of all "Alt+Tab windows" (even full screen UWP windows) and retrieve the handle of the one picked by the user
[英]not all application windows show after leaving and returning with ALT/TAB
當我的應用程序顯示主窗口以及一個較小的模式窗口(通過ShowDialog打開)的頂部時,我遇到了ALT / TAB的問題。 當我使用ALT / TAB轉到另一個應用程序,然后返回到我的應用程序時,僅顯示模式窗口,主窗口消失了。 這只是光學的東西。 沒有功能上的問題。 主窗口具有ShowInTaskbar =“ False”,因為我不希望用戶能夠使用ALT / TAB將不活動的主窗口置於最前面。 有人知道解決這個問題的辦法嗎?
我做了一個非常簡單的示例:
在您的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>
在代碼背后
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
new Dialog(this).ShowDialog();
}
}
在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>
並在對話框代碼后面
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;
目的是在模式窗口上的已激活和已禁用事件中處理此功能。
希望能幫助到你。
(如果使用的是MVVM,則必須重構以在WindowService類上或通過使用EventToCommand方法來處理)
編輯>>>當ShowInTaskbar =“ False”時,這適用於您的情況。 =)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.