我寫了一個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,並且從未見過這種行爲......嘗試用父窗口和子窗口創建非常簡單的項目,看看它是否發生在那裏 –