我想用这个简单的代码搜索任何可见的子窗口,但消息一直说找不到窗口。任何人都可以知道在主窗口中搜索可见子窗口吗?
这是代码:
private HomeWindow NewHomeWindow = new HomeWindow();
string ReturnWindowName;
private void btnhome_Click(object sender, RoutedEventArgs e)
{
ReturnWindowName = "NewHomeWindow";
NewHomeWindow.Owner = this;
NewHomeWindow.Show();
}
private void btnsearchwindow_Click(object sender, RoutedEventArgs e)
{
ChangeWindow();
}
public void ChangeWindow()
{
Window mySearchWindow = (Window)this.FindName(ReturnWindowName);
if (mySearchWindow != null)
{
MessageBox.Show("Window Found");
}
else
{
MessageBox.Show("Window Not Found");
}
}