2

I have a PasswordBox in a WPF application that is used on a touch screen without keyboard. This is a problem since the virtual keyboard icon is not shown when the PasswordBox is clicked.

I get the feeling it should have something to do with InputMethod and its IsInputMethodEnabled property, but the following still does not work:

<PasswordBox InputMethod.IsInputMethodEnabled="True"/>

Is it possible to force the virtual keyboard to pop up?


As a workaround I created a custom virtual keyboard that directly modifies the PasswordBox.Password..

Wouter
  • 2,170
  • 1
  • 28
  • 58

4 Answers4

1

Because of the virtual keyboard bug on tablets with the password box, I had to come up with a solution and the other suggestion listed here was not a good one. (Text was still readable, just slightly obfuscated.)

Here is the workaround:

<TextBox Name="Password" Text="{Binding Path=Password, UpdateSourceTrigger=PropertyChanged}" Height="50"

         Margin="0,4,0,10" FontFamily="Courier New"

         Foreground="{Binding ElementName=Password, Path=Background}">

            <TextBox.TextDecorations>

                <TextDecorationCollection>

                    <TextDecoration Location="Strikethrough" PenThicknessUnit="FontRenderingEmSize" >

                        <TextDecoration.Pen>
                            <Pen Brush="Black" Thickness="0.5" DashCap="Round" StartLineCap="Round" EndLineCap="Round">
                                <Pen.DashStyle>
                                    <DashStyle Dashes="0.0, 1.2" Offset="0.6"/>
                                </Pen.DashStyle>
                            </Pen>
                        </TextDecoration.Pen>

                    </TextDecoration>

                </TextDecorationCollection>

            </TextBox.TextDecorations>
        </TextBox>

MSDN Source: https://msdn.microsoft.com/en-us/library/system.windows.controls.passwordbox(VS.90).aspx

Gopichandar
  • 2,742
  • 2
  • 24
  • 54
1

I believe that the PasswordBox control does'nt support this, because it is not directly inherited from a TextBox. Instead it is inherited from control.

I have no direct answer for you, but there are some really bad workarounds for this problem

a) the propably best way to do is to create you own control which inherits from textbox.

b) you can put a textbox over the passwordbox. When the user clicks on it you handle the textboxes GotFocus event, hide the textbox and give the focus to you password box.

c) you can programmatically start the "osk.exe" which will also bring the keyboard to the front

StefanG
  • 239
  • 3
  • 12
  • B: this does not work for me, the keyboard icon is not shown. C: this works, but closing the window afterwords doesn't work, also it shows the full keyboard layout with numeric keypad included. I will try out suggestion A. – Wouter Sep 14 '11 at 13:08
0

Is it possible to force the virtual keyboard to pop up?

Yes, it is: How to make WPF input control show virtual Keyboard when it got focus in touch screen

Community
  • 1
  • 1
no.Oby
  • 107
  • 8
0

This is supported natively in newer versions of WPF running on Windows 10 Anniversary Update.

We use the WPFTabTip library to add this support to other versions of Windows.

Wouter
  • 2,170
  • 1
  • 28
  • 58
  • Is this work on win 7. I tried with win 7 on desktop PC and it is not working. – Milan Kocic May 29 '17 at 13:51
  • The github page states support for 8.1 and 10. I think the TabTip panel is Windows 8 and higher, but I'm not sure. Microsoft changed from OSK to TabTip at some point. – Wouter May 29 '17 at 15:49
  • There is tabtip on win 7, too. – Milan Kocic May 31 '17 at 11:47
  • FYI this no longer works automatically on the latest windows version (1803). Using automation (System.Windows.Automation.Peers.UIElementAutomationPeer.CreatePeerForElement(yourPasswordBox);) kind of solve the issue,but it is still quirky, for example, if you move from a textbox to a password box, TabTip closes, and you need to tap the passwordbox a second time. I get the same odd behavior with the WPFTabTip library. This is for regular WPF applications (not UWP). – Snellface Jul 03 '18 at 08:23