Home > Net >  There was a problem WPF access to all Windows
There was a problem WPF access to all Windows

Time:02-23

Public partial class Window for testing: the Window
{
Public void init ()
{
WindowCollection WindowCollection=App. Current. Windows;
Foreach (Window Window in windowCollection)
{
List2. Items. The Add (window. The Title);
}
}
Public Window for testing ()
{
InitializeComponent ();
init();
}
}
This code is used to retrieve the current window, and insert it into the ListBox named list2, but in actual operation, I only opened the three Windows, more than five items, there are two show not to come out, want to please the great god what is this,
Results:
1. The Window1
2. (no content) blank,
3. Window2
4. (no content) blank,
5. Window3
I am a high school student, the self-study of the holidays WPF some knowledge, knowledge is not strong in some places, hoping to make allowance for it

CodePudding user response:

 WindowCollection WindowCollection=App. Current. Windows; 
Foreach (Window Window in windowCollection)
{
If (window is the window) ListBox1. Items. The Add (window. The Title);
}

CodePudding user response:

reference 1/f, rabbit party at large response:
 WindowCollection WindowCollection=App. Current. The Windows; 
Foreach (Window Window in windowCollection)
{
If (window is the window) ListBox1. Items. The Add (window. The Title);
}

The output of the same..

CodePudding user response:

reference 1/f, rabbit party at large response:
 WindowCollection WindowCollection=App. Current. The Windows; 
Foreach (Window Window in windowCollection)
{
If (window is the window) ListBox1. Items. The Add (window. The Title);
}

I just now I set a breakpoint debugging and got the following value:
1. WpfApp. Window1
2. {. Microsoft VisualStudio. DesignTools. WpfTap. WpfVisualTreeService. Adorners. AdornerWindow} this show not to come out, but the debugging can see
3. WpfApp. Window2
4. {. Microsoft VisualStudio. DesignTools. WpfTap. WpfVisualTreeService. Adorners. AdornerWindow} to keep up with the same 2
5. WpfApp. Window3

2 and 4 of the Title value is empty, so there is no show, the great god can explain what this is
  •  Tags:  
  • C#
  • Related