Skip to content

Touch bug/issue with ShowDialog and TextBox #2491

Open

Description

@vsfeedback

This issue has been moved from a ticket on Developer Community.


Hello I'm developing a WPF application to be used with touch devices (Running Win 10 full).

There is one scenario where the touch stops responding as expected.
If I have a TextBox and open a dialog (ShowDialog()) then the dialog won't handle any touch and will ignore the user:

A) 1 touch ignored - if using single touch driver.

B) 10 touches ignored - if using multi touch driver.

And after that it starts responding normally again.

I have attached a video show casing this issue and also a test project so you can easily replicate (using Windows Simulator w/ touch or a touch monitor)
In the video you can see that when opening the dialog through a button it responds as expected but if opened through a TextBox it will then have a touch issue.

textbox-showdialog-touch-issue.mp4

ms-wpf-testtouchdialogs.zip

The code being used is just this:

        private void TextBox_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            // This cause touch issues within the dialog.
            // (1 touch ignored w/ single touch monitor/driver - 10 touches ignored w/ multi touch monitor/driver)
            new DialogWindow(). ShowDialog();
        }

private void Button_Click(object sender, RoutedEventArgs e)
{
new DialogWindow(). ShowDialog();
}

Windows 10
VS 2019
.NET 4.6.1 (but it was also tested with 4.8, exactly same issue)


Original Comments

Visual Studio Feedback System on 1/20/2020, 06:41 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

Visual Studio Feedback System on 1/30/2020, 01:12 PM:

This issue is currently being investigated. Our team will get back to you if either more information is needed, a workaround is available, or the issue is resolved.


Original Solutions

(no solutions)

Activity

  1. added this to the Future milestone on Feb 6, 2020
  2. added
    Bug
    on Feb 6, 2020
  3. qtbui159 commented on Feb 9, 2020

    @qtbui159

    This is an irritated and old bug which exists from .net framework 3.5. All first touch of non-button popup window(modal)would be ignored

  4. wcfCode commented on Jul 30, 2020

    @wcfCode

    Hope the problem gets attention.

  5. wcfCode commented on Jul 31, 2020

    @wcfCode

    Is there a temporary solution?

  6. qtbui159 commented on Jul 31, 2020

    @qtbui159

    Is there a temporary solution?

    你所有需要弹窗的地方都用button来做就行

  7. MitSeven commented on Aug 11, 2020

    @MitSeven

    I have the same error. I wonder why it takes 10 touches. I am currently doing a temporary fix using Dispatcher.BeginInvoke or DispatcherInvokeAsync

  8. Mzazvor commented on Mar 4, 2021

    @Mzazvor

    Hi,
    @MitSeven Could you elaborate on your temporary fix? I had spend few hours looking for progress in this problem and there seems to be none. We do unfortunately have those same 10touches on our showDialog window.

    Thanx for any advice
    Martin

  9. Mzazvor commented on Mar 4, 2021

    @Mzazvor

    For anyone after me... I managed to get it somewhat working with the use of StylusDownEvent.

    private void Button_StylusDown(object sender, System.Windows.Input.StylusDownEventArgs e)
    {
    var vm = (DressingPopupViewModel)this.DataContext;
    Button _myButton = (Button)sender;
    string value = _myButton.CommandParameter.ToString();
    if (vm.CanDoCommand(value))
    {
    vm.DoCommand(value);
    }
    e.Handled = true;
    }

    This method handles touches, where Binding to command of VM handles mouseClicks with no problem. It is probably not a clean solution but it is a few lines worth trying in your problem.

  10. GuangSunshine commented on May 7, 2021

    @GuangSunshine

    I had similar issue on a Button in my code, and the fix is rather simple for me -- do NOT handle the Touch and PreviewMouse events, just let the touch be promoted to Click event and do things there: <Button Click="btnClick">. If you requirement allows you to do that in your case, that should be the solution. If you can't wait till the Click event, please read on:

    My analysis of this problem:

    1. When a Button is being touched, WPF use one instance of some handler (let's call it touchHandler1 of type FingerTouchEventHandler) to handle the whole tunneling and bubbling events from PreviewTouchDown until the final TouchUp. If in the PreviewTouchUp or even TouchUp event handler, you show a new dialog or a MessageBox, the focus is switched to the new dialog, the touchHandler1 on the Button gets stuck, it does not get handled completely.

    2. If now you touch again, the WPF sees there is already one active FingerTouchEventHandler -- touchHandler1 and it is still active, so it wrongly thinks the user is putting a second finger on the screen, WPF proudly thinks "I can handle multi-touch!", so it creates touchHandler2, but since now there are two fingers on the screen, somehow the "second finger" is also stuck, so nothing happens on the screen;

    3. Same thing happens when the third touch occurs, WPF creates touchHandler3. This goes on and on until the 11th touch happens. WPF only supports 10 multi-touches (because human beings have 10 fingers), now it treat this 11th touch as part of the tunneling and bubbling sequence of touchHandler1, and completes touchHandler1. Subsequent touches complete the touchHandler2 etc, now everything is back to normal again.

    The above points 1, 2, 3 are my guess, they matches my observation well, then the solution could now also be obvious:
    in your TextBox_PreviewMouseDown(), BEFORE calling new DialogWindow(). ShowDialog(); just say e.Handled = true; I tried this solution in my code, it works for me. Please give it a try and let us know the result. Good luck!

  11. lasharn commented on Nov 15, 2021

    @lasharn

    BEFORE calling new DialogWindow(). ShowDialog(); just say e.Handled = true;

    This didn't work for me although your explanation for the underlying issue does make sense to me.

    I did try what @MitSeven suggested and call ShowDialog() within a Dispatcher.BeginInvoke call and that did work for me.

    This makes sense with your explanation since queuing the dialog call won't let the button get stuck during the event handler and therefore no extra touch handlers will be created.

  12. marcauto commented on Feb 9, 2022

    @marcauto

    Is this a problem only with Windows 10 or is a problem also in the other Windows (7, p.e)?

  13. GuangSunshine commented on Feb 9, 2022

    @GuangSunshine

    Only tried on Windows 10, do not know about other Windows.

  14. marcauto commented on Feb 17, 2022

    @marcauto

    for the ones that don't need the multi touch functionality, is possible to deactivate the multi touch driver?

  15. heathleger commented on Aug 1, 2022

    @heathleger

    Is there a temporary solution?

    你所有需要弹窗的地方都用button来做就行
    不懂你说的意思, new Button(). ShowDialog()??

  16. 8 remaining items

  17. isasin commented on Sep 17, 2022

    @isasin

    I see thanks for the answer I will try. so in that case, lets say I am using mouse and touch at the same time, then which handler should I use after I call this DisableWPFTabletSupport method? If I use mousedown event handler for touch too, does this matter? What do you say?

  18. Mzazvor commented on Sep 19, 2022

    @Mzazvor

    I see thanks for the answer I will try. so in that case, lets say I am using mouse and touch at the same time, then which handler should I use after I call this DisableWPFTabletSupport method? If I use mousedown event handler for touch too, does this matter? What do you say?

    I just call it once on app startup. For clicks i just use regular command binding with mouse event and MVVM structure.

    You will probably have to try that. I dont have any device to test it at the moment.

  19. heathleger commented on Feb 8, 2023

    @heathleger

    My solution to this problem is currently to call this method on startup.

    public static void DisableWPFTabletSupport(){
    	// Get a collection of the tablet devices for this window.
    	TabletDeviceCollection devices = Tablet.TabletDevices;
    	if (devices.Count > 0)
    	{
    		// Get the Type of InputManager.  
    		Type inputManagerType = typeof(InputManager);
    	
    		// Call the StylusLogic method on the InputManager.Current instance.  
    		object stylusLogic = inputManagerType.InvokeMember("StylusLogic",
    								BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
    								null, InputManager.Current, null);
    	
    		if (stylusLogic != null)
    		{
    			//  Get the type of the stylusLogic returned from the call to StylusLogic.  
    			Type stylusLogicType = stylusLogic.GetType();
    	
    			// Loop until there are no more devices to remove.  
    			while (devices.Count > 0)
    			{
    				// Remove the first tablet device in the devices collection.  
    				stylusLogicType.InvokeMember("OnTabletRemoved",
    								BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.NonPublic,
    								null, stylusLogic, new object[] { (uint)0 });
    			}
    		}
    	}
    }
    

    Thanks, this sample resolve my problem, but i still need the "StylusLogic". I use "Manipulation" to zoom ui element. There is a native smoth animation during user operating, The animation not work afther I remove the "StylusLogic". Please let me know how to fix this.

  20. keeleycenc commented on Sep 16, 2026

    @keeleycenc

    We are experiencing a similar issue in a WPF application targeting .NET 8 on Windows 10 with a touchscreen.

    The affected window is opened using ShowDialog().

    Observed behavior:

    • The close (X) button requires approximately 10 touch attempts before the window closes.
    • During unsuccessful attempts, the close button does not show its hover background. When the background finally lights up, the button responds and the window closes.
    • The maximize button works on every touch.
    • Both buttons belong to the same custom title bar and derive from the standard WPF Button.
    • The close buttons in our main window and a separate non-modal window work on the first touch. They use the same custom title bar.
    • The problem is consistently reproducible across repeated tests.

    Our dynamic UI code has paths that call ShowDialog() synchronously from PreviewMouseLeftButtonDown or PreviewMouseLeftButtonUp handlers.

    Could this be related to the issue reported here, even though the maximize button consistently works? Is there a confirmed fix or a recommended workaround for .NET 8?

    90c89c6a27db7685c3762c847b93c102.mp4
  21. miloush commented on Sep 16, 2026

    @miloush
    Contributor

    @keeleycenc would you have a simple repro project?

  22. keeleycenc commented on Sep 17, 2026

    @keeleycenc

    @keeleycenc would you have a simple repro project?

    We are trying to fix and create a minimal reproducible application, which may take some time

  23. keeleycenc commented on Sep 18, 2026

    @keeleycenc

    @miloush Here is a minimal repro.

    It is a dependency-free WPF application (net8.0-windows, no NuGet packages) with the
    input pipeline instrumented, so the failure mode can be read directly off the dialog.
    A touch screen is required; it does not reproduce with a mouse.

    Steps

    1. Build and run WpfModalTouchRepro.sln.
    2. Leave Host ScrollViewer has PanningMode=Both checked (the default).
    3. Touch the REPRO button, which calls ShowDialog() from PreviewMouseLeftButtonDown.
    4. Touch the button inside the dialog repeatedly and count the attempts.

    The first ten touches are discarded; the eleventh is handled. The counters in the
    dialog show:

    TouchDown 11 StylusDown 11 MouseDown 1 Click 1
    Distinct TouchDevice.Id values: 10

    TouchDown and StylusDown increase on every attempt, so the input does reach the
    window. MouseDown and Click stay at zero until the eleventh attempt, so it is never
    promoted to mouse input.

    The number of distinct TouchDevice.Id values stops at ten. Each of the first ten
    attempts is assigned a new touch device, so WPF treats every one of them as an
    additional finger. The eleventh attempt does not allocate an eleventh device: the pool
    is exhausted, and the input is instead delivered as part of the first sequence, which
    is still open. That sequence then completes, which is why MouseDown and Click reach
    one on exactly the eleventh attempt.

    Two independent conditions

    The first determines whether touches are discarded at all, the second how many.
    Measured on one machine with unchanged touch hardware and drivers:

    Dialog opened from Ancestor ScrollViewer with PanningMode other than None Touches discarded
    PreviewMouseLeftButtonDown yes 10
    PreviewMouseLeftButtonDown no 1
    Click yes 0
    Click no 0

    1. ShowDialog() is called before the touch sequence completes. The nested message
    loop prevents TouchUp from reaching the active touch device, which can therefore never
    complete. Opening the dialog from Click avoids this, because promotion has already
    finished by then.

    2. Touch is routed through the manipulation pipeline. With PanningMode.None
    promotion is immediate and only a single touch device gets stuck. Otherwise promotion
    is deferred and stuck devices accumulate.

    This may refine the original report, which attributed the difference between "1 touch
    ignored" and "10 touches ignored" to single-touch versus multi-touch drivers. In the
    table above the only variable was the PanningMode of an ancestor ScrollViewer.

    Condition 2 is easy to satisfy without knowing it. NavigationViewContentPresenter in
    WPF-UI hosts page content in a DynamicScrollViewer that ships with PanningMode=Both
    and IsManipulationEnabled=True. Note also that setting VerticalScrollBarVisibility
    to Disabled does not turn off touch panning, as PanningMode is a separate property.

    Additional observation

    While the dialog content is unresponsive, the close button in its title bar still
    responds to the first touch. The title bar is a Win32 non-client area, so that input is
    handled by the window manager and never enters WPF's touch promotion pipeline. The
    window is therefore still receiving input normally, and only input that has to be
    promoted is affected. This is also why our application lost its close button as
    originally reported: it draws its own title bar as WPF content, which is an ordinary
    element in the client area.

    Deferring the ShowDialog() call with Dispatcher.BeginInvoke(DispatcherPriority.Input, ...)
    reduces the discarded touches from ten to at most one, but does not eliminate them:
    whether TouchUp is delivered before the queued callback runs depends on how long the
    finger stays down. The README in the attachment lists the workarounds we evaluated.

    Attachment

    Video

    5d814976039f43c0727a3111fa11f1ce.mp4

    Source code

    Reproduction.zip

  24. added
    Priority:1
    on Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🚧 work in progressBugPR ProposedPriority:1Wave1area-Touch

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions