Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I discovered by setting breakpoints that the first time you type in a textbox, WPF reads the public <code>SystemParameters.MouseVanish</code> property which calls <code>SystemParametersInfo(SPI_GETMOUSEVANISH, ...)</code> to get the mouse vanish setting. Subsequent calls to <code>SystemParameters.MouseVanish</code> use the cached value.</p> <p>Two possible solutions:</p> <ol> <li>Access <code>SystemParameters.MouseVanish</code>, then use reflection to overwrite the cached result so subsequent calls return false.</li> <li>Call Win32's <code>SystemParametersInfo(SPI_SETMOUSEVANISH, ...)</code> to turn off vanish (with no notify), then access <code>SystemParameters.MouseVanish</code>, then call <code>SystemParametersInfo(SPI_SETMOUSEVANISH, ...)</code> to set it back to its prior value (with no notify)</li> </ol> <p>Either of these can be done at any time before the user starts typing in the textbox.</p> <p>Here is how the reflection solution would look:</p> <pre><code>void LocallyDisableMouseVanish() { if(SystemParameters.MouseVanish) foreach(var field in typeof(SystemParameters).GetFields(BindingFlags.NonPublic | BindingFlags.Static) if(field.Name.Contains("mouseVanish")) field.SetValue(null, false); } </code></pre> <p>For ordinary purposes doing this once would be enough, but there is a possibility that the user will change settings while your app is running, which would cause the MouseVanish value to be reloaded on next access. If you want to guard against this, use HwndSource.AddHook to hook WM_SETTINGCHANGE and schedules a callback to re-apply the fix:</p> <pre><code>const int WM_SETTINGCHANGE = 26; public void AddSettingChangeHook() { _settingChangeWatcher = new HwndSource(new HwndSourceParameters("WM_SETTINGSCHANGE watcher")); _settingChangeWatcher.AddHook((IntPtr hwnd, IntPtr msg, IntPtr wParam, IntPtr lParam, ref bool handled) =&gt; { if((int)msg == WM_SETTINGCHANGE) Dispatcher.Invoke(DispatcherPriority.Input, new Action(() =&gt; { LocallyDisableMousePointerVanish(); }); }); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload