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 ... >
<i:Interaction.Behaviors>
<Einstein:FullScreenBehavior
FullScreenOnDoubleClick="True"
FullScreenOnMaximize="True"
RestoreOnEscape="True" />
</i:Interaction.Behaviors>
</Window>
The attached demo includes the FullScreenBehavior.cs which has no external dependencies. Enjoy.

cool, thanks! works like a charm.
Hello,
Nice behavior and tip !
As I am pointing out in my blog’s post (http://blog.lexique-du-net.com/index.php?post/2010/09/23/Quick-tip-%3A-My-WPF-Fullscreen-window-still-display-a-border-on-right-and-bottom-side…-how-to-remove-it) without putting the ResizeMode to NoResize, some borders may still be visible …
Have a nice day :-)
Very interesting, thanks man!
I would like more interactivity on full-screen mode such as: (1) key toggle between than only press ESC backing to normal state. (2) when i restore the window to normal mode, it should keep pre-state before it is made full-screen.
So, i added your code.
(1) Support to toggle modes - creates a new attached property that names FullScreenKey, Key type, its default value is F11 (like common WebBrowers) - in Window_KeyDown method involves the keyDown event, add a if statement
(2) Keep pre-state of the window - In OnIsFullScreenChanged handler method, changes little … if (newValue) { // stores its pre-fullscreen state window.Tag = window.WindowState;
….
quite great, happy coding!
Hi Josh,
I’m having some trouble compiling this in VS2010 with the BlendSLSDK_en.msi installed to get the Interactivity dll. I’m getting the following error:
Error 1 Unknown build error, ‘Cannot resolve dependency to assembly ‘System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e’ because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event.’ FullScreenDemo
Unfortunately does not work with RibbonWindow that is derived from window. (Part of Microsoft Ribbon for WPF) http://stackoverflow.com/questions/6956036/wpf-fullscreen-in-ribbonwindow