I'm trying to find how to make a WPF app true fullscreen like you'd see in Direct3D without using Direct3D. This article demonstrates how to do most of what I'm looking for. However, it lacks two things that I must know how to achieve.
The aforementioned article is essentially what you'd see referred to as a fullscreen border or Borderless Window in most places. To be explicitly clear, this allows the mouse cursor to leave the window when using multiple monitors. I cannot have it do that (I will but that's a separate "mode" like you'd see in most video games).
The Solution presented must also be recognized by the OS as a fullscreen application so that Windows 10 features such as focus assist work properly.
I have looked for solutions to this and have read many articles though none truly answer my question. The one I mentioned above is closest to what I'm looking for it satisfactorily answered most of my questions regarding this such as covering the start menu but those two points are left unanswered.
The relevant parts of the MainWindow
class would look something like this. What I need to know is how to force the cursor to stay within the bounds of the Main Window and how to have the Main Window treated as a full-screen application by the OS. For the first part with the cursor subscribing to and Handling the MouseLeave
event seems to do exactly what I want however I have yet to find a way to prevent it from leaving the window (See the TODO below in the event handler).
MainWindow.xaml
<NavigationWindow x:Class="MyApp.Client.Windows.Windows.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="My App"
Background="#353535"
Width="1920" Height="1080"
WindowStyle="None"
ResizeMode="NoResize"
WindowState="Maximized"
WindowStartupLocation="CenterScreen"
ShowsNavigationUI="False"
MouseLeave="MainWindow_OnMouseLeave">
</NavigationWindow>
MainWindow.xaml.cs
public partial class MainWindow
{
#region Constructors
public MainWindow()
{
InitializeComponent();
}
#endregion
#region Methods
private void MainWindow_OnMouseLeave(object sender, MouseEventArgs e)
{
if (Application.Current.MainWindow == null) return;
Rect windowBounds = new Rect(new Size(Application.Current.MainWindow.Width, Application.Current.MainWindow.Height));
Point mousePosition = Mouse.GetPosition(this);
if (mousePosition.X > windowBounds.X || mousePosition.Y > windowBounds.Y || mousePosition.X < 0 || mousePosition.Y < 0)
{
// TODO: Force cursor to stay within window bounds.
}
}
#endregion
}