Creating Single-Instance Windows
At times you may want to create a single-instance window--a window that has only one instance. If a user selects a single-instance window multiple times, it simply brings the selected window to front (if it's hidden behind another window).
To create a single instance window, you can implement the Singleton design pattern. For example, the MM .NET sample application's User Window is single instance and implements the Singleton pattern by means of this static (Shared), read-only property.
In C#:
public static UserWindow Instance
{
get
{
if (_instance == null || !_instance.IsLoaded)
_instance = new UserWindow();
return _instance;
}
}
private static UserWindow _instance;<</pre>>And in VB .NET:
Public Shared ReadOnly Property Instance() As UserWindow
Get
If _instance Is Nothing OrElse Not _instance.IsLoaded Then
_instance = New UserWindow()
End If
Return _instance
End Get
End Property
Private Shared _instance As UserWindowTo instantiate the form, you can call the Window Manager's Show() method like this in C#:
mmAppWPF.WindowMgr.Show(UserWindow.Instance, this);And in VB .NET:
mmAppWPF.WindowMgr.Show(UserWindow.Instance, Me)
© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 10/23/10
Comment or report problem with topic
