Skip to content

WPF topmost window Cannot touch in tablet #2054

Open

Description

@lindexi
  • .NET Core Version: (e.g. 3.0 Preview1, or daily build number, use dotnet --info) 3.0
  • Windows version: (winver) All version
  • Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
  • Is this bug related specifically to tooling in Visual Studio No

Problem description:

All you need is two tablets (or other touch device) and a WPF window set topmost. Here is the demo.

<Window x:Class="WpfApp6.MainWindow"
        xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="https://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="https://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:options="https://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
        xmlns:local="clr-namespace:WpfApp6"
        mc:Ignorable="d" Topmost="True" 
        Title="MainWindow" Height="350" Width="525">
    <Border x:Name="RootBorder" Width="740" Height="480" Background="Green" >
    </Border>
</Window>

Next, plug in these two tablets (called T1&T2) in turn, and run the demo.(you can run the demo first, if you like. it doesn't change the result).Everythin is fine,it works.

BUT, when you plug out the second tablet (T2), you will find the demo cannot response for any touch message from the first one(T1). Until you close this window, or plug out and plug in T1 again.(Well other parts in you computer do get the touch message from T1, as well as other windows in your demo but this topmost window)

I made some efforts to figure out why. And it seems that there is some hooks didn't remove when a TouchDevice is disconnected.But I can't go any further.

A good news is I found a way by chance, may fix this bug.

use

new WindowInteropHelper(this).EnsureHandle();

in constructor. Or just call this method BEFORE the window show,like

var window =new TopmostWindow();
new WindowInteropHelper(window).EnsureHandle();
window.show();

The bug will disapper.

But who want add this in every topmost window.By the way, it seems to have a conflict with AllowTransparent=True in some cases.

Hope this bug get fixed soon.

Copied from: WPF topmost window Cannot touch in tablet - Developer Community

Activity

  1. weltkante commented on Oct 16, 2019

    @weltkante

    Just for the record, I don't like placing this workaround in constructors, I have bad experiences in WinForms forcing handle creation in a constructor because it changes the control flow of how the handles get created, events are fired etc., leading to hard to find bugs in other places. Looking forward to a real fix.

  2. added
    Bug
    on Oct 16, 2019
  3. added this to the Future milestone on Oct 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugarea-Touch

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions