FullScreenBehavior makes full-screen apps in WPF easy

Download FullScreenDemo Project

So now I’m working on an application that will be used at a trade show in a booth. Customers will come up to the application and type in the area code and exchange of their phone number and the application will tell them whether or not they can move their phone number over to us. Piece of cake. But obviously a battleship gray Windows Forms application will simply not do. I chose WPF for the project because it needs to access an offline database, interact with an external COM server (MapPoint), and run full screen with keyboard input.

That last point is what led me to the code I posted tonight. Running a WPF application in full screen mode is pretty trivial.

  • Set WindowStyle = None
  • Set TopMost = True
  • Set WindowState = Maximized

But coming off a recent Silverlight project, I was a little perturbed about the fact that Silverlight can easily “go full screen” and back whereas in WPF it felt really manual. Plus there were a few other improvements I wanted to make that I could easily wrap up into a reusable behavior. For one, using a full-screen window during debugging is a pain in the ass, even with two monitors. Therefore, I want to be able to toggle full screen mode at runtime.

Here are a few common ways that applications enter and exit full screen mode. This behavior supports them all.

  • Many full-screen apps allow the user to toggle full screen mode by double clicking inside the window.
  • Many full-screen apps allow the user to exit full screen mode by pressing escape.
  • Many full-screen apps implicitly enter full screen mode when the window is maximized.

The only one that was tricky was the last one. Since WPF does not have a “StateChanging” event, what was happening was the Window (with its border and title bar) is maximized before the event is raised. By that time, setting the WindowStyle property to remove the caption and border didn’t affect the maximized size so the maximized window was still showing the taskbar. It took a little trial and error but I settled on using WM_SYSCOMMAND.

Usage of the behavior is simple.

<Window ... >


                RestoreOnEscape="True" />



The attached demo includes the FullScreenBehavior.cs which has no external dependencies. Enjoy.

Full Screen Demo