Understanding a Window Properties in WPF

In this article, we will discuss some important properties of the window object in WPF. Here we set the properties with the help of an example. We begin with the properties.

AllowTransparency Property: If we want to set the window as the Transparent window, we set the AllowTransparency property to "True".

<
Window x:Class="Window_Properties_In_WPF.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  
    Title
="Window1" Height="300" Width="300"
AllowsTransparency="True" WindowStyle="None">

Clipboard01.jpg
Note: We also set the WindowStyle="None" property. As if we can't set this property, we can't set the AllowTransparency property.

Cursor: By this, we change the cursor style when the mouse points on the window:

<Window x:Class="Window_Properties_In_WPF.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title
="Window1" Height="300" Width="300" AllowsTransparency="True" Cursor="Pen"
    BorderBrush="BlueViolet" BorderThickness="5" Background="Beige" WindowStyle="None">

Background: By this we can set the background color of the window.


Window
x:Class="Window_Properties_In_WPF.Window1"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns
:x="http://schemas.microsoft.com/winfx/2006/xaml"

   Title="Window1" Height="300" Width="300" AllowsTransparency="True"
Background="Beige" WindowStyle="None">

The Output Will Be:

pic2.png

BorderBrush: By this property, we can set the color of the Border:


<
Window x:Class="Window_Properties_In_WPF.Window1"
   xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

   Title="Window1" Height="300" Width="300" AllowsTransparency="True"
BorderBrush="BlueViolet" 
   BorderThickness
="5" Background="Beige"  WindowStyle="None">

The output will be:

pic3.png

BorderThickness: By this property we set theThickness of the Border like this:

<
Window x:Class="Window_Properties_In_WPF.Window1"
    xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns
:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title
="Window1" Height="300" Width="300" AllowsTransparency="True"
    BorderBrush
="BlueViolet"
BorderThickness="5" Background="Beige" WindowStyle="None">

Icon: By this property we set the icon on the Taskbar; if we set the ShowInTaskBar property to True and we also set it on the upperleft corner of the Window.

<Window x:Class="Window_Properties_In_WPF.Window1"
    xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns
:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title
="Window1" Height="300" Width="300" AllowsTransparency="True"   Cursor="Pen"
    ShowInTaskbar="True" Icon="C:/Users/dell/Desktop/Window Properties In WPF/Window
    Properties In WPF/Image/Chrysanthemum.jpg" BorderBrush="BlueViolet"
    BorderThickness
="5" Background="Beige" WindowStyle="None">

pic4.png
IsEnabled: When this property is set to True. The window is available to receive the user input. And if it is false the window is unable to receive user input.

<
Window x:Class="Window_Properties_In_WPF.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns
:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title
="Window1" Height="300" Width="300" AllowsTransparency="True"
IsEnabled="False" 
    Cursor="Pen" ShowInTaskbar="True" Icon="C:/Users/dell/Desktop/Window
    Properties In WPF/Window Properties In WPF/Image/Chrysanthemum.jpg"

    BorderBrush
="BlueViolet" BorderThickness="5" Background="Beige" WindowStyle="None">

pic5.png

ResizeMode: By this property, we can resize the window at run time. When we set it NoResize, we can't resize it. And when we set it to CanResize, we can resize it. And the CanMinimize property allows the user to minimize the window. CanResizeWithGrip is also used to resize the window but it adds a cue on the right hand corner of the window.

WindowStartupLocation: It is used to determine the startup location of the window. If we set it to Manual then we can set its left and top corner. And if we set it to CenterScreen, it will be shown in the center of the screen. And if we set it to CenterOwner, it will be set to the center of the Owner Form.


<
Window x:Class="Window_Properties_In_WPF.Window1"
   xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns
:x="http://schemas.microsoft.com/winfx/2006/xaml"

   Title
="Window1" Height="300" Width="300" AllowsTransparency="True"  
   WindowStartupLocation="CenterScreen"  IsEnabled="False"
   ResizeMode="CanMinimize"  Cursor="Pen" ShowInTaskbar="True"
   Icon="C:/Users/dell/Desktop/Window Properties In WPF/Window Properties In
   WPF/Image/Chrysanthemum.jpg"
BorderBrush="BlueViolet"
   BorderThickness
="5" Background="Beige" WindowStyle="None">

SizeToContent: By this property, the window resizes itself automatically to fit its content. We can resize the window manually or we can change its width and height with the help of this property like this:

<
Window x:Class="Window_Properties_In_WPF.Window1"
   xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   Title
="Window1" Height="300" Width="300" AllowsTransparency="True"
   SizeToContent="Height"  IsEnabled="False"  ResizeMode="CanMinimize" 
   Cursor="Pen" ShowInTaskbar="True" Icon="C:/Users/dell/Desktop/Window
   Properties In WPF/Window Properties In WPF/Image/Chrysanthemum.jpg"

   BorderBrush
="BlueViolet" BorderThickness="5" Background="Beige" WindowStyle="None">

pic6.png


Up Next
    Ebook Download
    View all
    Learn
    View all