以下代碼演示了我在關閉子窗口時將父窗口最小化的問題,我不希望發生這種情況。關閉子窗口使父項最小化
class SomeDialog : Window
{
protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
{
base.OnMouseDoubleClick(e);
new CustomMessageBox().ShowDialog();
}
}
class CustomMessageBox : Window
{
public CustomMessageBox()
{
Owner = Application.Current.MainWindow;
}
}
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
{
base.OnMouseDoubleClick(e);
new SomeDialog() { Owner = this }.Show();
}
}
Window1是主應用程序窗口。
SomeDialog是一個窗口,彈出Window1中的某個事件(在示例中雙擊window1),該窗口需要是無模式。
CustomMessageBox是一個窗口,可以彈出某個事件在「SomeDialog」中的某個事件(雙擊該示例中的SomeDialog),該窗口需要爲模態。
如果您運行該應用程序,然後雙擊Window1的內容以調出SomeDialog,然後雙擊SomeDialog的內容以調出CustomMessagebox。
現在關閉CustomMessagebox。精細。
現在,如果關閉SomeDialog,Window1會最小化?爲什麼它最小化,我該如何阻止它?
編輯:看起來解決方法很簡單,使用Viv提出的技術。
class SomeDialog : Window
{
protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
{
base.OnMouseDoubleClick(e);
new CustomMessageBox().ShowDialog();
}
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
base.OnClosing(e);
Owner = null;
}
}
我與子窗口啓動一個進程打開一個目錄(例如'Process.Start(「C:\\」)')相同的問題。接受的答案爲我工作。 –