2011-09-18 70 views
0

我写了一个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(); 
    } 
} 
+0

你能添加简单的代码来重现这个问题吗?我已经使用XP和WIN7,并且从未见过这种行为......尝试用父窗口和子窗口创建非常简单的项目,看看它是否发生在那里 –

回答

1

不是一个完美的解决方案可言,但你总是可以订阅关闭事件应用类,并在事件处理程序取消申请截止。

0

在拨打childWindow.ShowDialog()之前,您是否确定您的childWindow.Owner已正确设置为我们的MainWindow?