ThinkGeo.com    |     Documentation    |     Premium Support

Map stealing focus from child windows on mouse over

Hi

I have a WPF application with multiple child windows. One of the child windows is using ThinkGeo 14.3.2 for WPF. When the mouse is over the map then the window with the map is moved to the front and the current child window is losing the focus.

when the mouse is over the map the focus is changed to the map window:

I have made a demo application in order to show the problem. Note in the demo application I have removed the raster maps due to permission.

DemoMapStealingFocus_2025_08_27.zip (20.8 KB)

Is there any suggestion about what is wrong ?
Thanks

Domenico

Hi Domenico,

The following code would fix the issue:

this.Activated += MainWindow_Activated;
this.Deactivated += MainWindow_Deactivated;

   private void MainWindow_Deactivated(object? sender, EventArgs e)
   {
       Map.IsHitTestVisible = false;
   }

   private void MainWindow_Activated(object? sender, EventArgs e)
   {
       Map.IsHitTestVisible = true;
   }

Thanks,
Ben

Hi Ben

Unfortunately, this is not a solution for us since setting

Map.IsHitTestVisible = false;

will prevent the application to receive the mouse over events.

Best regards

Domenico

Hi Domenico,

I tried a couple ways and seems the following one works the best

  Map.MouseMove += (sender, args) =>
  {
      // MouseMove will be raised even the Map Window is not being focused
      System.Diagnostics.Debug.WriteLine("MouseMove");
  };


// in MapWindow
protected override void OnSourceInitialized(EventArgs e)
{
    base.OnSourceInitialized(e);

    var hwnd = new WindowInteropHelper(this).Handle;
    int exStyle = (int)NativeMethods.GetWindowLong(hwnd, NativeMethods.GWL_EXSTYLE);
    NativeMethods.SetWindowLong(hwnd, NativeMethods.GWL_EXSTYLE, exStyle | NativeMethods.WS_EX_NOACTIVATE);
}

internal class NativeMethods
{
    public const int GWL_EXSTYLE = -20;
    public const int WS_EX_NOACTIVATE = 0x08000000;

    [DllImport("user32.dll")]
    internal static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex);

    [DllImport("user32.dll")]
    internal static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
}

Thanks,
Ben

Hi Ben

Thanks for your suggestion but this solution is still stealing the focus although the window is not brought to the front.

At the moment we will down prioritize this topic in our application.

Is any plan from ThinkGeo to work on this item in future releases ? If so when ?

Best regards

Domenico

Hi Domenico,

All right, I see what you want. can you create a custom MapView like following see if it works for you?

  public class MyMapView : MapView
  {
      public MyMapView()
      {
          FocusableProperty.OverrideMetadata(typeof(MyMapView),
              new FrameworkPropertyMetadata(false));
      }
  }

We’ve also integrated this change to the latest beta.

Thanks,
Ben

Hi Ben

Thanks. Great.
This is working for our application

Best regards
Domenico

That’s awesome! :grinning:

Hi

A little correction for the code:

public MyMapView()
      {
          FocusableProperty.OverrideMetadata(typeof(MyMapView),
              new FrameworkPropertyMetadata(false));
      }

Need to be changed to:

static MyMapView()
      {
          FocusableProperty.OverrideMetadata(typeof(MyMapView),
              new FrameworkPropertyMetadata(false));
      }

Otherwise the method will raise an exception the next time it is invoked

Thanks for sharing! :+1: