Every WPF window starts with a root element.
Usually, this is the Window.
Example:
<Window>
</Window>
This represents the application’s main window.
Everything visible on the screen must be placed inside this root element.
A Typical Window #
<Window
x:Class="Demo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Demo"
Width="600"
Height="400">
<Grid>
</Grid>
</Window>
Here:
- Window is the root element.
- Grid is the content.
- Controls go inside the Grid.
Window Properties #
The root window has many useful properties.
Title #
Sets the window title.
Title="Inventory System"
Width #
Sets the width.
Width="800"
Height #
Sets the height.
Height="600"
ResizeMode #
Controls whether users can resize the window.
ResizeMode="NoResize"
Options include:
- CanResize
- NoResize
- CanMinimize
WindowStartupLocation #
Determines where the window appears.
WindowStartupLocation="CenterScreen"
Background #
Sets the background color.
Background="LightGray"
Icon #
Specifies the window icon.
Icon="Images/logo.ico"
