Skip to content

WPF topmost window Cannot touch in tablet #2054

@lindexi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions