-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TouchKeyboardWin10MainWindow.xaml.cs
58 lines (50 loc) · 1.8 KB
/
TouchKeyboardWin10MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright © 2019 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
using System.Windows;
using CefSharp.Enums;
using Microsoft.Windows.Input.TouchKeyboard;
namespace CefSharp.Wpf.Example
{
/// <summary>
/// TouchKeyboardWin10MainWindow provides a very basic Windows 10 only example of
/// showing the onscreen(virtual) keyboard in a WPF app.
/// </summary>
public partial class TouchKeyboardWin10MainWindow : Window
{
private TouchKeyboardEventManager touchKeyboardEventManager;
public TouchKeyboardWin10MainWindow()
{
InitializeComponent();
Browser.VirtualKeyboardRequested += BrowserVirtualKeyboardRequested;
Browser.IsBrowserInitializedChanged += BrowserIsBrowserInitializedChanged;
}
private void BrowserIsBrowserInitializedChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if ((bool)e.NewValue)
{
var browserHost = Browser.GetBrowserHost();
touchKeyboardEventManager = new TouchKeyboardEventManager(browserHost.GetWindowHandle());
}
else
{
if (touchKeyboardEventManager != null)
{
touchKeyboardEventManager.Dispose();
}
}
}
private void BrowserVirtualKeyboardRequested(object sender, VirtualKeyboardRequestedEventArgs e)
{
var inputPane = touchKeyboardEventManager.GetInputPane();
if (e.TextInputMode == TextInputMode.None)
{
inputPane.TryHide();
}
else
{
inputPane.TryShow();
}
}
}
}