WPF - Window

Window is the root window of XAML applications 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 example.
When you create a new WPF project, then by default, the Window control is present. Let’s have a look at the following example.
The following XAML code starts with a <Window> Tag and ends with a </Window> tag. The code sets some properties for the window and creates some other controls like text blocks, button, etc.
The following XAML code starts with a <Window> Tag and ends with a </Window> tag. The code sets some properties for the window and creates some other controls like text blocks, button, etc.
<Window x:Class = "WPFToolTipControl.MainWindow" 
   xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
   xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml" 
   xmlns:d = "http://schemas.microsoft.com/expression/blend/2008" 
   xmlns:mc = "http://schemas.openxmlformats.org/markup-compatibility/2006" 
   xmlns:local = "clr-namespace:WPFToolTipControl" 
   mc:Ignorable = "d" Title = "MainWindow" Height = "350" Width = "604"> 
	
   <Grid> 
      <TextBlock x:Name = "textBlock" HorizontalAlignment = "Left"  
         Margin = "101,75,0,0" TextWrapping = "Wrap"  
         Text = "User Name" VerticalAlignment = "Top" /> 
			
      <TextBlock x:Name = "textBlock1" HorizontalAlignment = "Left"
         Margin = "101,125,0,0" TextWrapping = "Wrap"  
         Text = "Password" VerticalAlignment = "Top" /> 
			
      <TextBox x:Name = "textBox" HorizontalAlignment = "Left"  
         Height = "24" Margin = "199,75,0,0" TextWrapping = "Wrap"  
         VerticalAlignment = "Top" Width = "219"  
         ToolTipService.ToolTip  =  "Enter User Name" /> 
			
      <PasswordBox x:Name = "passwordBox" HorizontalAlignment = "Left"  
         Margin = "199,125,0,0" VerticalAlignment = "Top" Width = "219"  
         Height = "24" ToolTipService.ToolTip  =  "Enter Password" /> 
			
      <Button x:Name = "button" Content = "Log in" HorizontalAlignment = "Left"  
         Margin = "199,189,0,0" VerticalAlignment = "Top" Width = "75"  
         ToolTipService.ToolTip = "Log in" /> 
   </Grid> 
	
</Window> 
When you compile and execute the above code, it will display the following output. When the mouse enters the region of the Button or the Textboxes, it will show a tooltip.
We recommend that you execute the above example code and try some other properties and events of this class.

    31 Lectures 
     2.5 hours 

 Anadi Sharma

    30 Lectures 
     2.5 hours 

 Taurius Litvinavicius
 Print
 Add Notes
 Bookmark this page