C#遍历所有窗口


1、

 1 App.Current.Dispatcher.Invoke((System.Action)(() =>
 2                 {
 3                     foreach (Window window in Application.Current.Windows)
 4                     {
 5                         var mdv =window.Content as MessageDialogView;
 6                         if (mdv != null)
 7                         {
 8                             var mdvm = mdv.DataContext as MessageDialogViewModel;
 9 
10                             if (mdvm != null && mdvm.DisplayName == "Dialog Box" )
11                             {
12                                 if ( (!IsLP1Placed && mdvm.Text.Contains("LP1"))
13                                 || (!IsLP2Placed && mdvm.Text.Contains("LP2"))
14                                 || (!IsLP3Placed && mdvm.Text.Contains("LP2"))
15                                 || (!IsLP4Placed && mdvm.Text.Contains("LP2")) )
16                                     mdvm.TryClose();
17                             }
18                         }
19                     }
20                 }));
C