Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Window size not affected by TabTip keyboard

I have a WPF application running on a Windows 8.1 tablet. the application is using the following method to show the virtual keyboard:

public static void OpenKeyboard()
{
    ProcessStartInfo startInfo =
        new ProcessStartInfo(@"C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe")
        {
            WindowStyle = ProcessWindowStyle.Hidden
        };
    Process.Start(startInfo);
}

However, the size of the active window that the keyboard is displayed on top of doesn't change accordingly, meaning that if I have a ScrollViewer surrounding all the elements of my window it doesn't respond to the keyboard.
Is there any way to make my windows aware of the keyboard presence?
Update
Tried registering to the SizeChanged event of the window but it's not raised when the keyboard pops up.

like image 562
Yoav Avatar asked May 27 '15 12:05

Yoav


2 Answers

Since TabTip.exe is a separate process it doesn't fire any events in your WPF application. Since win 8.1 tabtip does not automatically resize windows anymore. (there have been a lot of complaints about it)

There are a couple of ways you can do this manually. Firstly, Win8 apps have so called "LayoutAware" pages. Something similar can be done in WPF using the VisualStateManager. This is rather complex and might not be the best solution, but I included it nevertheless (VisualStateManager solution here

Another way is to get the tabtip process from the list of active processes and calculate its width and height and use it to manually resize your screens. Tabtip is if I remember correctly about 270 in height. You can also directly resize your screens as soon as the process appears. Something like this;

  public void OpenKeyboard()
         {
             ProcessStartInfo startInfo =
                 new ProcessStartInfo(@"C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe")
                 {
                     WindowStyle = ProcessWindowStyle.Hidden
                 };
             Process.Start(startInfo);

             //this = your window
             this.Height -= 270;

         }

There is another more clean way. It is a bit difficult and I haven't tried it myself yet. It is possible to grab the process and resize it where you want. You might be able to do it with the Windows API call 'findWindow()', but as far as I know that doesn't always work with tabtip, you might have to use P/Invoke. To get you started I found some pretty great sources from which I wont steal credit by copying the code here; How to resize another application's window in C#

Changing another applications size and position using P/invoke (win32)

I hope you find this info useful. I know how you feel and have struggled with tabtip myself more often than id like.

Footnote; isn't it easier to just decrease your max window height and move it to the top of the screen when osk is called and put it back when its killed?

like image 97
Daan Avatar answered Nov 09 '22 23:11

Daan


As far as I know this happens if the window is maximized or not resizable. Mke sure its state is not maximized before opening the keyboard.

like image 37
Manuel R. Wenk Avatar answered Nov 10 '22 00:11

Manuel R. Wenk