Skip to content

WPF should not show the touch keyboard for read-only fields #1133

Open

Description

@rladuca
  • .NET Core Version: 4.7.1+
  • Windows version: (winver): RS1+
  • Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes

Problem description:
WPF uses direct calls to InputPane.TryShow via TipTsfHelper when the focused control implements the text UIA pattern, UIA is already loaded, and if the OS is >= RS1.
This means that even if the exposed TextPattern is marked read-only, WPF will request the KB to show.

What is actually needed is a finer grained set of conditions.

  • Don't call TryShow if the TextPattern implementation declares it is read-only
  • Don't call TryShow if the focus tracking for the touch KB does not use UIA, but uses TSF (RS3+, but this needs confirmation).

This can be mitigated in later OSes (RS3+) by setting the AppContext flag DisableImplicitTouchKeyboardInvocation. This stops WPF from calling InputPane.TryShow but the KB focus tracking and invocation will still work.

Activity

  1. added
    Bug
    on Jul 1, 2019
  2. added this to the 5.0 milestone on Jul 1, 2019
  3. changed the title [-]WPF should not show the keyboard for read-only fields[/-] [+]WPF should not show the touch keyboard for read-only fields[/+] on Jul 1, 2019
  4. modified the milestones: 5.0.0, 7.0.0 on Aug 26, 2021
  5. rampaa commented on Aug 15, 2023

    @rampaa

    Any progress on this?

  6. lindexi commented on Aug 17, 2023

    @lindexi
    Member

    @rampaa It seems that the problem is not easy to fix

  7. rampaa commented on Aug 17, 2023

    @rampaa

    Here's what I've tried so far to workaround this issue:

    1. Setting TextBox's Focusable property to false if it's read only. This does solve the problem but creates other problems, e.g., user cannot select text, which is unacceptable in my case.

    2. Creating a new class that derives from TextBox and overriding OnCreateAutomationPeer like following:

    internal sealed class MyTextBox : TextBox
    {
        protected override AutomationPeer OnCreateAutomationPeer()
        {
            return IsReadOnly
                ? new FrameworkElementAutomationPeer(this)
                : base.OnCreateAutomationPeer();
        }
    }
    

    The problem with this approach is that the user can change whether the textbox is read-only or not in my app, but it doesn't seem like we can change the supplied AutomationPeer after OnCreateAutomationPeer is raised (I tried calling FrameworkElementAutomationPeer.FromElement(MyTextBoxInstance)?.InvalidatePeer() and FrameworkElementAutomationPeer.CreatePeerForElement(MyTextBoxInstance) to no avail) so whether or not touch keyboard shows up won't adapt to further changes to the IsReadOnly property of MyTextBox.

  8. miloush commented on Aug 17, 2023

    @miloush
    Contributor

    If you expect users to select (and copy) text, then you should have touch keyboard appear so that they can perform these tasks using keyboard.

  9. rampaa commented on Aug 17, 2023

    @rampaa

    No, that's not the desired behavior for my app. For the purposes of my app, touch keyboard should never show up unless TextBox's IsReadOnly property is set to false.

  10. rampaa commented on Jun 19, 2024

    @rampaa

    Will this be fixed in the future? Its milestone was set to 7.0.0 but obviously it isn't fixed even in 8.0.x.

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

    Bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions