本文介绍了当我在WPF中为其他窗口调用ShowDialog时,如何隐藏父窗口。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WPF应用程序中,一个窗口为其他窗口调用ShowDialog。我看到所有的窗户链。当我在显示其他窗口之前隐藏调用窗口时 - 当Visibility = System.Windows.Visibility.Visible时ShowDialog返回。对于所有窗口,我添加了this.Closed + = Window_Closed;显示上一个窗口

  void  Window_Closed( object  sender,EventArgs e)
{
if (Owner!= null
{
Owner.Visibility = System.Windows.Visibility.Visible;
}
}



和调用ShowDialog之前我隐藏了活动窗口

{

this.Visibility = System.Windows.Visibility.Collapsed;

CustomerData maCreateCD = new CustomerData();

maCreateCD.Owner = this;

maCreateCD.ShowDialog();

}

对其他窗口重复此操作,一切正常。我只看到最后一个窗口。但是当我在最后一个窗口中调用Close()时,我看到了maCreateCD.ShowDialog();返回,其他窗口返回ShowDialog。并且只有在此之后,将在最后一个之前调用的窗口的Visibility属性设置为Visible和窗口显示。

在MSDN中,仅在窗口关闭后返回ShowDialog,但这不起作用。我看到ShowDialog被返回,窗口没有关闭。

解决方案

In WPF Application one window call ShowDialog for other and other. And I see all window chain. When I hide the calling window before I show other - ShowDialog returns when Visibility = System.Windows.Visibility.Visible. For all windows I added this.Closed += Window_Closed; for show previous window

void Window_Closed(object sender, EventArgs e)
{
    if (Owner != null)
    {
            Owner.Visibility = System.Windows.Visibility.Visible;
    }
}


and before call ShowDialog I hide the active window
{
this.Visibility = System.Windows.Visibility.Collapsed;
CustomerData maCreateCD = new CustomerData();
maCreateCD.Owner = this;
maCreateCD.ShowDialog();
}
This operation repeated for other windows and all OK. I see only last window. But when I call Close() in last window I see that maCreateCD.ShowDialog(); is returned and for other windows ShowDialog is returned. And only after this the Visibility property for window called before last is set to Visible and window shows.
In MSDN ShowDialog is returned only after window closing but this does not work. I see that ShowDialog is returned and window does not closed.

解决方案


这篇关于当我在WPF中为其他窗口调用ShowDialog时,如何隐藏父窗口。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 15:52