66

I would like to make my WPF application fullscreen. Right now the start menu prevents it from covering everything and shifts my application up. This is what I have for my MainWindow.xaml code:

<Window x:Class="HTA.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    mc:Ignorable="d" 
    WindowStyle="None" ResizeMode="NoResize"
    WindowStartupLocation="CenterScreen" 
    Width="1024" Height="768">
Barn Monkey
  • 245
  • 3
  • 11
Robert
  • 6,086
  • 19
  • 59
  • 84

6 Answers6

156

You're probably missing the WindowState="Maximized", try the following:

<Window x:Class="HTA.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525"
    WindowStyle="None" ResizeMode="NoResize"  
    WindowStartupLocation="CenterScreen" WindowState="Maximized">
GEOCHET
  • 21,119
  • 15
  • 74
  • 98
Nuno Ramiro
  • 1,756
  • 1
  • 11
  • 4
8
<Window x:Class="HTA.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    mc:Ignorable="d" 
    ResizeMode="NoResize"
    WindowStartupLocation="CenterScreen" 
    Width="1024" Height="768"
    WindowState="Maximized" WindowStyle="None">

Window state to Maximized and window style to None

xmedeko
  • 7,336
  • 6
  • 55
  • 85
Jeba Ranganathan
  • 532
  • 1
  • 8
  • 5
3

You can also do it at run time as follows :

  • Assign name to the window (x:Name = "HomePage")
  • In constructor just set WindowState property to Maximized as follows

HomePage.WindowState = WindowState.Maximized;

GEOCHET
  • 21,119
  • 15
  • 74
  • 98
Chetan S
  • 935
  • 1
  • 11
  • 21
  • 8
    Should not use the codebehind for properties which can be set in xaml. – Peter van Kekem Apr 29 '13 at 14:06
  • 2
    @PetervanKekem This is pretty useful when the window is not maximized by default but rather gets maximized when user wants it to be by clicking a button, etc. – SepehrM Sep 30 '14 at 12:56
  • True, but in the answer it is set in the constructor. (When using the MVVM pattern, you should use the ViewModel class for this, and bind the WindowState to the property) – Peter van Kekem Sep 30 '14 at 14:02
3
window.WindowStyle = WindowStyle.None;
window.ResizeMode = ResizeMode.NoResize;
window.Left = 0;
window.Top = 0;
window.Width = SystemParameters.VirtualScreenWidth;
window.Height = SystemParameters.VirtualScreenHeight;
window.Topmost = true;

Works with multiple screens

Alex Zaitsev
  • 2,544
  • 5
  • 18
  • 27
2

When you're doing it by code the trick is to call

WindowStyle = WindowStyle.None;

first and then

WindowState = WindowState.Maximized;

to get it to display over the Taskbar.

kabinx
  • 35
  • 1
  • 4
1

If you want user to change between WindowStyle.SingleBorderWindow and WindowStyle.None at runtime you can bring this at code behind:

Make application fullscreen:

RootWindow.Visibility = Visibility.Collapsed;
RootWindow.WindowStyle = WindowStyle.None;
RootWindow.ResizeMode = ResizeMode.NoResize;
RootWindow.WindowState = WindowState.Maximized;
RootWindow.Topmost = true;
RootWindow.Visibility = Visibility.Visible;

Return to single border style:

RootWindow.WindowStyle = WindowStyle.SingleBorderWindow;
RootWindow.ResizeMode = ResizeMode.CanResize;
RootWindow.Topmost = false;

Note that without RootWindow.Visibility property your window will not cover start menu, however you can skip this step if you making application fullscreen once at startup.

SavageStyle
  • 61
  • 1
  • 11