Search code examples
c#wpftouchdesktop-application

WPF Toolbar Overflow Touchinteraction stops App responding to Input


Problem Description

When using Touch(screen) input to operate a Button inside the Overflow of a WPF Toolbar the App stops responding to Mouse and Touch inputs. Keyboard input or any code execution (even in UI Thread) seems to be not affected.Moving the mouse outside the Windows content Area releases the freeze and the App can be used again (until one uses the Overflow again).

It sometimes it happens directly with the first interaction, often you can operate the Button a few times before the "freeze" happens.

The "freezing" does not happen when using the Mouse to access the Button inside the Overflow.

Test Environment

I made a small Test Project to verify it is not something in my App and I was able to verify the Problem for .NET 4.5.2, 4.6.1 and 4.7.

It has been tested on two different Windows 7 PCs with different Touchscreens. Both with the same outcome.

Code:

<Window x:Class="ToolBarTest.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"
    xmlns:local="clr-namespace:ToolBarTest"
    mc:Ignorable="d"
    Title="MainWindow"
    Height="350"
    Width="525">
<DockPanel>
    <ToolBarTray DockPanel.Dock="Top">
    <ToolBar>
        <Button Content="New" />
        <Button Content="Open" />
        <Button Content="Save" />
    </ToolBar>
    <ToolBar>
        <Button Content="Cut" />
        <Button Content="Copy" />
        <Button Content="Paste" />
        <Button ToolBar.OverflowMode="Always">
            <Grid>
                <TextBlock Text="Testbutton" />
            </Grid>
        </Button>
        </ToolBar>
    </ToolBarTray>
    <TextBox AcceptsReturn="True" />
</DockPanel>

Additional thoughts

To me it looks like the Toolbar or the OverflowToggleButton is capturing the mouse device as soon as the Overflow Panel closes. Holding the Overflow Panel open does prevent the freeze (tested in my big App)


Solution

  • I crossposted the question on MSDN: https://social.msdn.microsoft.com/Forums/de-DE/c4e6061d-ecc1-4c7e-afe9-2587cfd2734d/fenster-bekommt-keine-maus-und-touchevents-mehr-nach-touch-interaktion-mit-toolbar-overflow?forum=wpfde

    The second Link from the marked answer in above Thread helped me: https://social.msdn.microsoft.com/Forums/de-DE/d964afd2-67d4-4dfb-b118-695ab07ef6c1/wpf-popups-and-touch-input-can-cause-ui-to-become-unresponsive?forum=wpf

    Basically in the Click Event from the Button inside the Overflow I force the MouseCapture to the Button and Release it again:

    Code Behind (not so emty anymore)

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            CaptureMouse();
            ReleaseMouseCapture();
        }