LMeyer
LMeyer

Reputation: 2631

Virtual Win8 keyboard in WebBrowser control

I'm currently doing a touch application in WPF. It works great so far but sometimes I need to launch the built-in web browser control. My problem is that despite that the zoom, scroll and such are working, I can't get the Windows 8 virtual keyboard (like in IE 11) to show up when the user gets the focus on web text inputs.

Is there any way to achieve such behavior ? Please keep in mind my WPF app is supposed to run topmost and entirely fullscreen all the time so I can't ask the user to bring up the virtual keyboard manually.

Upvotes: 1

Views: 1855

Answers (1)

LMeyer
LMeyer

Reputation: 2631

Finally found it here... As written, the Winforms WebBrowser has better wrapper for HTMLDocument, making it way easier than using MSHTML interop. Here's a code snippet :

C# :

public partial class BrowserWindow : Window
        {
            public BrowserWindow(string url)
            {
                InitializeComponent();
                WebView.ScriptErrorsSuppressed = true;
                WebView.AllowNavigation = true;
                WebView.Navigate(new Uri(url));
                WebView.DocumentCompleted += LoadCompleteEventHandler;
            }

            private void LoadCompleteEventHandler(object sender, WebBrowserDocumentCompletedEventArgs navigationEventArgs)
            {
                HtmlElementCollection elements = this.WebView.Document.GetElementsByTagName("input");
                foreach (HtmlElement input in elements)
                {
                    if (input.GetAttribute("type").ToLower() == "text")
                    {
                        input.GotFocus += (o, args) => VirtualKeyBoardHelper.AttachTabTip();
                        input.LostFocus += (o, args) => VirtualKeyBoardHelper.RemoveTabTip();
                    }
                }
            }
        }

XAML :

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
        x:Class="PlayPlatform.BrowserWindow"
        Title="Browser" ResizeMode="NoResize"  
        WindowStartupLocation="CenterScreen" WindowState="Maximized" Topmost="True" ShowInTaskbar="False" WindowStyle="None" AllowDrop="False" AllowsTransparency="False">
    <WindowsFormsHost HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <wf:WebBrowser x:Name="WebView" />
    </WindowsFormsHost>
</Window>

The VirtualKeyBoardHelper methods are manuallly launching and terminating tabtip.exe.

Upvotes: 2

Related Questions