- 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 - 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 −
|Sr.No.||Property & Description|
Gets or sets a value that indicates whether a window's client area supports transparency.
Gets or sets the dialog result value, which is the value that is returned from the ShowDialog method.
Gets or sets a window's icon.
Gets a value that indicates whether the window is active.
Gets or sets the position of the window's left edge, in relation to the desktop.
Gets a collection of windows for which this window is the owner.
Gets or sets the Window that owns this Window.
Gets or sets the resize mode.
Gets the size and location of a window before being either minimized or maximized.
Gets or sets a value that indicates whether a window is activated when first shown.
Gets or sets a value that indicates whether the window has a task bar button.
Gets or sets a value that indicates whether a window will automatically size itself to fit the size of its content.
Gets or sets the Windows 7 taskbar thumbnail for the Window.
Gets or sets a window's title.
Gets or sets the position of the window's top edge, in relation to the desktop.
Gets or sets a value that indicates whether a window appears in the topmost z-order.
Gets or sets the position of the window when first shown.
Gets or sets a value that indicates whether a window is restored, minimized, or maximized.
Gets or sets a window's border style.
|Sr.No.||Event & Description|
Occurs when a window becomes the foreground window.
Occurs when the window is about to close.
Occurs directly after Close is called, and can be handled to cancel window closure.
Occurs after a window's content has been rendered.
Occurs when a window becomes a background window.
Occurs when the window's location changes.
This event is raised to support interoperation with Win32. See HwndSource.
Occurs when the window's WindowState property changes.
|Sr.No.||Method & Description|
Attempts to bring the window to the foreground and activates it.
Manually closes a Window.
Allows a window to be dragged by a mouse with its left button down over an exposed area of the window's client area.
Returns a reference to the Window object that hosts the content tree within which the dependency object is located.
Makes a window invisible.
Opens a window and returns without waiting for the newly opened window to close.
Opens a window and returns only when the newly opened window is closed.
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.
Kickstart Your Career
Get certified by completing the courseGet Started