1

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.

  1. 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).

  2. 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
}
Hawkeye4040
  • 126
  • 10
  • Does this answer your question? [full screen wpf](https://stackoverflow.com/questions/15920067/full-screen-wpf) – oetzi Apr 27 '20 at 19:27
  • this looks like aslo close to achieve https://stackoverflow.com/questions/18721904/wpf-metro-window-full-screen – oetzi Apr 27 '20 at 19:30
  • Unfortunately, this does not answer my question at all. These are some of the articles I've found already that were unsatisfactory. As I state in my question I'm looking for something that will make it so the mouse does not leave the bounds of the window when you're using multiple monitors. – Hawkeye4040 Apr 27 '20 at 20:09
  • Maybe [this](https://stackoverflow.com/questions/850956/how-to-limit-cursor-movement-in-wpf-based-app) may help then. – aepot Apr 28 '20 at 13:56
  • It's certainly the right idea but unfortunately not. I know this is tangible to achieve I'm still looking myself all over. At the bottom of that article, someone mentioned the native API ClipCursor. That's really close to what I'm talking about to constrain the cursor to the window. When you only have one monitor what I have works fine as is. Once you add an additional monitor the cursor is able to leave the bounds of the window which is undesired when the application has focus. – Hawkeye4040 Apr 28 '20 at 22:57
  • Also, none of those "register" the application as a full-screen application to the OS so features like focus assist operate as expected. – Hawkeye4040 Apr 28 '20 at 22:57
  • It's a tougher one to solve than it first appears I know. – Hawkeye4040 Apr 28 '20 at 22:58

0 Answers0