
- XAML Tutorial
- XAML - Home
- XAML - Overview
- XAML - Environment Setup
- Writing XAML Aplication On MAC OS
- XAML Vs C# Code
- XAML Vs.VB.NET
- XAML - Building Blocks
- XAML - Controls
- XAML - Layouts
- XAML - Event Handling
- XAML - Data Binding
- XAML - Markup Extensions
- XAML - Dependency Properties
- XAML - Resources
- XAML - Templates
- XAML - Styles
- XAML - Triggers
- XAML - Debugging
- XAML - Custom Controls
- XAML Useful Resources
- XAML - Quick Guide
- XAML - Useful Resources
- XAML - Discussion
XAML - Window
It is the root window of an XAML application which provides minimize/maximize option, Title bar, border, and close button. It also provides the ability to create, configure, show, and manage the lifetime of windows and dialog boxes. The hierarchical inheritance of Window class is as follows −

Properties
Sr.No. | Property & Description |
---|---|
1 | AllowsTransparency Gets or sets a value that indicates whether a window's client area supports transparency. |
2 | DialogResult Gets or sets the dialog result value, which is the value that is returned from the ShowDialog method. |
3 | Icon Gets or sets a window's icon. |
4 | IsActive Gets a value that indicates whether the window is active. |
5 | Left Gets or sets the position of the window's left edge, in relation to the desktop. |
6 | OwnedWindows Gets a collection of windows for which this window is the owner. |
7 | Owner Gets or sets the Window that owns this Window. |
8 | ResizeMode Gets or sets the resize mode. |
9 | RestoreBounds Gets the size and location of a window before being either minimized or maximized. |
10 | ShowActivated Gets or sets a value that indicates whether a window is activated when first shown. |
11 | ShowInTaskbar Gets or sets a value that indicates whether the window has a task bar button. |
12 | SizeToContent Gets or sets a value that indicates whether a window will automatically size itself to fit the size of its content. |
13 | TaskbarItemInfo Gets or sets the Windows 7 taskbar thumbnail for the Window. |
14 | Title Gets or sets a window's title. |
15 | Top Gets or sets the position of the window's top edge, in relation to the desktop. |
16 | Topmost Gets or sets a value that indicates whether a window appears in the topmost z-order. |
17 | WindowStartupLocation Gets or sets the position of the window when first shown. |
18 | WindowState Gets or sets a value that indicates whether a window is restored, minimized, or maximized. |
19 | WindowStyle Gets or sets a window's border style. |
Events
Sr.No. | Event & Description |
---|---|
1 | Activated Occurs when a window becomes the foreground window. |
2 | Closed Occurs when the window is about to close. |
3 | Closing Occurs directly after Close is called, and can be handled to cancel window closure. |
4 | ContentRendered Occurs after a window's content has been rendered. |
5 | Deactivated Occurs when a window becomes a background window. |
6 | LocationChanged Occurs when the window's location changes. |
7 | SourceInitialized This event is raised to support interoperation with Win32. See HwndSource. |
8 | StateChanged Occurs when the window's WindowState property changes. |
Methods
Sr.No. | Method & Description |
---|---|
1 | Activate Attempts to bring the window to the foreground and activates it. |
2 | Close Manually closes a Window. |
3 | DragMove Allows a window to be dragged by a mouse with its left button down over an exposed area of the window's client area. |
4 | GetWindow Returns a reference to the Window object that hosts the content tree within which the dependency object is located. |
5 | Hide Makes a window invisible. |
6 | Show Opens a window and returns without waiting for the newly opened window to close. |
7 | ShowDialog Opens a window and returns only when the newly opened window is closed. |
Example
When you create a new WPF project, then by default, the Window control is present. Let’s have a look at the following XAML code which starts from Window Tag and ends with </Window> tag. We have also defined some properties as well for the window.
<Window x:Class = "XAMLToolTip.MainWindow" xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml" Title = "MainWindow" Height = "350" Width = "604"> <Grid> <StackPanel Orientation = "Vertical"> <Button Content = "Button with a simple ToolTip." ToolTipService.ToolTip = "Simple ToolTip" Width = "200" Margin = "50" /> <!-- A TextBlock with an offset ToolTip. --> <TextBlock Text = "TextBlock with an offset ToolTip." Width = "200" Margin = "50"> <ToolTipService.ToolTip> <ToolTip Content = "Offset ToolTip." HorizontalOffset = "20" VerticalOffset = "30"/> </ToolTipService.ToolTip> </TextBlock> </StackPanel> </Grid> </Window>
When you compile and execute the above code with the mouse entering the Window, it will produce the following output −

We recommend you to execute the above example code and experiment with some other properties and events.