//File:Window.xaml.vb Imports System Imports System.Collections.Generic Imports System.ComponentModel Imports System.Windows Imports System.Windows.Controls Imports System.Windows.Documents Imports System.Windows.Media Namespace WpfApplication1 Public Partial Class Window1 Inherits Window Public Sub New() InitializeComponent() End Sub Private Sub Window1_Loaded(sender As Object, e As RoutedEventArgs) For i As Integer = 1 To 5 Dim window As New Window() SetupWindow(window, "Window " & i) window.Show() Next RebuildWindowList() End Sub Private Sub SetupWindow(window As Window, title As String) AddHandler window.Closing, New CancelEventHandler(AddressOf Window_Closing) AddHandler window.Closed, New EventHandler(AddressOf Window_Closed) window.Title = title window.Width = 100.0 window.Height = 100.0 window.Content = title End Sub Private Sub RebuildWindowList() Dim windows As New List(Of Window)() For Each window As Window In Application.Current.Windows If window Is Me Then Continue For End If windows.Add(window) Next lbxWindows.ItemsSource = windows End Sub Private Sub Window_Closed(sender As Object, e As EventArgs) RebuildWindowList() End Sub Private Sub Window_Closing(sender As Object, e As CancelEventArgs) Dim w As Window = TryCast(sender, Window) If w Is Nothing Then Return End If e.Cancel = Not cbxCanClose.IsChecked = True End Sub Private Sub CheckBox_Checked_Changed(sender As Object, e As RoutedEventArgs) Dim window As Window = TryCast(lbxWindows.SelectedItem, Window) If window Is Nothing Then Return End If If cbxIsVisible.IsChecked = True Then window.Show() Else window.Hide() End If End Sub Private Sub btnBringToFront_Click(sender As Object, e As RoutedEventArgs) Dim window As Window = TryCast(lbxWindows.SelectedItem, Window) If window IsNot Nothing Then window.Activate() End If End Sub Private Sub btnClose_Click(sender As Object, e As RoutedEventArgs) Dim window As Window = TryCast(lbxWindows.SelectedItem, Window) If window IsNot Nothing Then window.Close() End If End Sub End Class End Namespace