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 −
AllowsTransparency
Gets or sets a value that indicates whether a window's client area supports transparency.
DialogResult
Gets or sets the dialog result value, which is the value that is returned from the ShowDialog method.
Icon
Gets or sets a window's icon.
IsActive
Gets a value that indicates whether the window is active.
Left
Gets or sets the position of the window's left edge, in relation to the desktop.
OwnedWindows
Gets a collection of windows for which this window is the owner.
Owner
Gets or sets the Window that owns this Window.
ResizeMode
Gets or sets the resize mode.
RestoreBounds
Gets the size and location of a window before being either minimized or maximized.
ShowActivated
Gets or sets a value that indicates whether a window is activated when first shown.
ShowInTaskbar
Gets or sets a value that indicates whether the window has a task bar button.
SizeToContent
Gets or sets a value that indicates whether a window will automatically size itself to fit the size of its content.
TaskbarItemInfo
Gets or sets the Windows 7 taskbar thumbnail for the Window.
Title
Gets or sets a window's title.
Top
Gets or sets the position of the window's top edge, in relation to the desktop.
Topmost
Gets or sets a value that indicates whether a window appears in the topmost z-order.
WindowStartupLocation
Gets or sets the position of the window when first shown.
WindowState
Gets or sets a value that indicates whether a window is restored, minimized, or maximized.
WindowStyle
Gets or sets a window's border style.
Activated
Occurs when a window becomes the foreground window.
Closed
Occurs when the window is about to close.
Closing
Occurs directly after Close is called, and can be handled to cancel window closure.
ContentRendered
Occurs after a window's content has been rendered.
Deactivated
Occurs when a window becomes a background window.
LocationChanged
Occurs when the window's location changes.
SourceInitialized
This event is raised to support interoperation with Win32. See HwndSource.
StateChanged
Occurs when the window's WindowState property changes.
Activate
Attempts to bring the window to the foreground and activates it.
Close
Manually closes a Window.
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.
GetWindow
Returns a reference to the Window object that hosts the content tree within which the dependency object is located.
Hide
Makes a window invisible.
Show
Opens a window and returns without waiting for the newly opened window to close.
ShowDialog
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.
 Print
 Add Notes
 Bookmark this page