Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
Window Class
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
Window Class

Updated: July 2008

Provides the ability to create, configure, show, and manage the lifetime of windows and dialog boxes.

Namespace:  System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/xaml/presentation
Visual Basic (Declaration)
<LocalizabilityAttribute(LocalizationCategory.Ignore)> _
<UIPermissionAttribute(SecurityAction.InheritanceDemand, Window := UIPermissionWindow.AllWindows)> _
Public Class Window _
    Inherits ContentControl
Visual Basic (Usage)
Dim instance As Window
C#
[LocalizabilityAttribute(LocalizationCategory.Ignore)]
[UIPermissionAttribute(SecurityAction.InheritanceDemand, Window = UIPermissionWindow.AllWindows)]
public class Window : ContentControl
Visual C++
[LocalizabilityAttribute(LocalizationCategory::Ignore)]
[UIPermissionAttribute(SecurityAction::InheritanceDemand, Window = UIPermissionWindow::AllWindows)]
public ref class Window : public ContentControl
JScript
public class Window extends ContentControl
XAML Object Element Usage
<Window>
  Content
</Window>

The point of interaction between a user and a standalone application is a window. A Windows Presentation Foundation (WPF) window consists of two distinct areas:

  • A non-client area, which hosts the windows adornments, including an icon, title, System menu, minimize button, maximize button, restore button, close button, and a border.

  • A client area, which hosts application-specific content.

A standard window is shown in the following figure:

Window elements

Window encapsulates the ability to create, configure, show, and manage the lifetime of both windows and dialog boxes, and provides the following key services:

Lifetime Management: Activate, Activated, Close, Closed, Closing, Deactivated, Hide, IsActive, Show, SourceInitialized.

Window Management: GetWindow, OwnedWindows, Owner.

Appearance and Behavior: AllowsTransparency, ContentRendered, DragMove, Icon, Left, LocationChanged, ResizeMode, RestoreBounds, ShowActivated, ShowInTaskbar, SizeToContent, StateChanged, Title, Top, Topmost, WindowStartupLocation, WindowState, WindowStyle

Dialog Boxes: DialogResult, ShowDialog.

Additionally, Application exposes special support for managing all of the windows in an application:

  • Application maintains a list of all the windows that are currently instantiated in the application. This list is exposed by the Windows property.

  • By default, MainWindow is automatically set with a reference to the first Window that is instantiated in an application. This thereby making the window the main application window.

A Window can be implemented using markup, markup and code-behind, or code.

Window is primarily used to display windows and dialog boxes for standalone applications. However, for applications that require navigation at the window level, such as wizards, you can use NavigationWindow instead; NavigationWindow derives from Window and extends it with browser-style navigation support.

ms590112.alert_note(en-us,VS.90).gifNote:

Islands of navigable content can be incorporated into other content and content containers using Frame.

Window needs UnmanagedCode security permission to be instantiated. This has the following consequences:

  • ClickOnce-deployed standalone applications will request permission elevation when launched from either the Internet or Local Intranet zones.

  • XBAPs that request anything less than full permissions will not be able to instantiate windows or dialog boxes.

See Windows Presentation Foundation Security Strategy - Platform Security for a discussion on standalone application deployment and security considerations.

Content Model: Window is a ContentControl, which means that Window can contain content such as text, images, or panels. Also, Window is a root element and, consequently, cannot be part of another element's content. For more information about the content model for Window, see Content Models.

The following example shows how a standard window is defined using only markup:

C#
<Window 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    Title="Main Window in Markup Only" 
    Height="300" 
    Width="300" />

The following example shows how a standard window is defined using only code:

C#
using System;
using System.Windows;

namespace CSharp
{
    public partial class CodeOnlyWindow : Window
    {
        public CodeOnlyWindow()
        {
            this.Title = "Main Window in Code Only";
            this.Width = 300;
            this.Height = 300;
        }
    }
}

The following example shows how a standard window is defined using a combination of markup and code-behind.

C#
<Window 
    x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Main Window" 
    Height="300" 
    Width="300" />

C#
using System;
using System.Windows;
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows Vista

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0

Date

History

Reason

July 2008

Added new members: ShowActivated property, ShowActivatedProperty field.

SP1 feature change.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker