我写了一个WPF程序,当用户点击一个按钮时,会弹出一个新窗口。WPF Windows XP中的儿童Windows问题
我曾尝试用展()或的ShowDialog()函数以显示新的窗口。
在Windows 7,当用户关闭子窗口时,主窗口将保留,程序不会退出。这种行为是我想要的。
但是,当程序运行在Windows XP,当用户关闭子窗口时,主窗口将一起关闭,整个程序将退出。
我试图设置在窗口类不同性质的不同的价值,最后,我发现,当我设置子窗口属性“ShowInTaskbar”为“False”程序不仅会退出。
但是,如果ShowInTaskbar设置为false,则用户无法在任务栏中找到不是我想要的行为的条目。
我想要的真的很简单。我只是希望在Windows XP中运行的程序与在Windows 7中运行的程序在用户关闭子窗口时具有相同的行为(即当用户关闭子窗口时,主窗口不会退出)。此外,我想在任务栏中输入一个新创建的子窗口(即ShowInTaskbar = true)。
有没有人有任何关于这个问题的想法?
主窗口
<Window x:Class="ChildWindowTest.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 Click="OpenChild">Open Child Window</Button>
</Grid>
</Window>
代码对于主窗口:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void OpenChild(object sender, RoutedEventArgs e)
{
ChildWindow child = new ChildWindow();
child.Owner = this;
//child.ShowInTaskbar = false; <--- if comment, the program will exit, when child window closed
child.Show();
}
}
子窗口:
<Window x:Class="ChildWindowTest.ChildWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ChildWindow" Height="300" Width="300">
<Grid>
</Grid>
代码子窗口:
public partial class ChildWindow : Window
{
public ChildWindow()
{
InitializeComponent();
}
}
你能添加简单的代码来重现这个问题吗?我已经使用XP和WIN7,并且从未见过这种行为......尝试用父窗口和子窗口创建非常简单的项目,看看它是否发生在那里 –