I found by setting breakpoints that when I first entered a text field, WPF reads a public property SystemParameters.MouseVanishthat calls SystemParametersInfo(SPI_GETMOUSEVANISH, ...)to set the mouse value. Subsequent calls SystemParameters.MouseVanishuse a cached value.
Two possible solutions:
SystemParameters.MouseVanish, , false.- Win32
SystemParametersInfo(SPI_SETMOUSEVANISH, ...), ( ), SystemParameters.MouseVanish, SystemParametersInfo(SPI_SETMOUSEVANISH, ...), ( )
, .
:
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);
}
, , , MouseVanish . , HwndSource.AddHook WM_SETTINGCHANGE :
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) =>
{
if((int)msg == WM_SETTINGCHANGE)
Dispatcher.Invoke(DispatcherPriority.Input, new Action(() =>
{
LocallyDisableMousePointerVanish();
});
});
}