0
我以編程方式創建了一個新的窗口和框架,以導航到單獨的頁面(身份驗證)。關閉窗口後,我想做一些事情,但if
聲明永遠不會返回false。檢查窗口是否打開不起作用
Window newWindow = new Window();
Page authentication = new Authentication();
Frame newFrame = new Frame();
newWindow.Title = "Authentication";
newWindow.Content = newFrame;
newFrame.NavigationService.Navigate(authentication);
newWindow.Show();
if (IsWindowOpen<Window>("Authentication") == false)
{
//DO THINGS HERE
}
這是我IsWindowOpen
方法:
public static bool IsWindowOpen<T>(string name = null) where T : Window
{
return string.IsNullOrEmpty(name)
? Application.Current.Windows.OfType<T>().Any()
: Application.Current.Windows.OfType<T>().Any(w => w.Title.Equals(name));
}
我設法打開新窗口並運行單獨的頁面,但收盤時沒有任何反應。我在if語句中添加了一行打印行,並且不打印。