MainWindow.xaml
<Window xClass="HelloWorld.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlnsx="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
Width="200"
SizeToContent="Height">
<Grid>
<StackPanel>
<Button Click="NewWindowCliecked">New Window Cliecked</Button>
<Button Click="ListOpenWindow">List OpenWindow</Button>
</StackPanel>
</Grid>
</Window>
MainWindow.xaml.cs
using System.Text;
using System.Windows;
namespace HelloWorld {
public partial class MainWindow : Window {
static int _createcount;
public MainWindow() {
InitializeComponent();
Title = "ウィンドウ" + _createcount;
_createcount++;
}
<summary>
</summary>
<param name="sender"></param>
<param name="e"></param>
void NewWindowCliecked(object sender, RoutedEventArgs e) {
new MainWindow().Show();
}
<summary>
</summary>
<param name="sender"></param>
<param name="e"></param>
void ListOpenWindow(object sender, RoutedEventArgs e) {
StringBuilder sb = new StringBuilder();
foreach (Window w in Application.Current.Windows) {
sb.AppendLine(w.Title);
}
MessageBox.Show(sb.ToString(), "Open Window");
}
}
}
検証