监听软键盘的显示/隐藏事件(Windows 8.1 RT,XAML)
Listen the show / hide events for soft keyboard (Windows 8.1 RT, XAML)
我如何知道我的应用程序或页面中的软键盘何时 shown/dismissed?
在 THIS 文章中找到了这个片段。但对 WP 8.1 RT 无效。我如何翻译它或获得类似的行为?
public class MyApplication
{
public MyApplication()
{
// Grab the input pane for the main application window and attach
// touch keyboard event handlers.
Windows.Foundation.Application.InputPane.GetForCurrentView().Showing
+= new EventHandler(_OnInputPaneShowing);
Windows.Foundation.Application.InputPane.GetForCurrentView().Hiding
+= new EventHandler(_OnInputPaneHiding);
}
private void _OnInputPaneShowing(object sender, IInputPaneVisibilityEventArgs eventArgs)
{
// If the size of this window is going to be too small, the app uses
// the Showing event to begin some element removal animations.
if (eventArgs.OccludedRect.Top < 400)
{
_StartElementRemovalAnimations();
// Don't use framework scroll- or visibility-related
// animations that might conflict with the app's logic.
eventArgs.EnsuredFocusedElementInView = true;
}
}
private void _OnInputPaneHiding(object sender, IInputPaneVisibilityEventArgs eventArgs)
{
if (_ResetToDefaultElements())
{
eventArgs.EnsuredFocusedElementInView = true;
}
}
private void _StartElementRemovalAnimations()
{
// This function starts the process of removing elements
// and starting the animation.
}
private void _ResetToDefaultElements()
{
// This function resets the window's elements to their default state.
}
}
您引用的文章适用于 Windows 运行时应用程序,但它有一个小错误。 InputPane is in Windows.UI.ViewManagement 不在 Windows.Foundation.Application。更改它,其余的应该可以正常工作。
我已经报告了文档错误,因此可以修复它。
找到答案,报名那些活动就够了:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
InputPane.GetForCurrentView().Showing += onKeyboardShowing;
InputPane.GetForCurrentView().Hiding += onKeyboardHidding;
}
private void onKeyboardShowing(InputPane sender, InputPaneVisibilityEventArgs args)
{
KeyboardVisible = true;
}
private void onKeyboardHidding(InputPane sender, InputPaneVisibilityEventArgs args)
{
KeyboardVisible = false;
}
我如何知道我的应用程序或页面中的软键盘何时 shown/dismissed?
在 THIS 文章中找到了这个片段。但对 WP 8.1 RT 无效。我如何翻译它或获得类似的行为?
public class MyApplication
{
public MyApplication()
{
// Grab the input pane for the main application window and attach
// touch keyboard event handlers.
Windows.Foundation.Application.InputPane.GetForCurrentView().Showing
+= new EventHandler(_OnInputPaneShowing);
Windows.Foundation.Application.InputPane.GetForCurrentView().Hiding
+= new EventHandler(_OnInputPaneHiding);
}
private void _OnInputPaneShowing(object sender, IInputPaneVisibilityEventArgs eventArgs)
{
// If the size of this window is going to be too small, the app uses
// the Showing event to begin some element removal animations.
if (eventArgs.OccludedRect.Top < 400)
{
_StartElementRemovalAnimations();
// Don't use framework scroll- or visibility-related
// animations that might conflict with the app's logic.
eventArgs.EnsuredFocusedElementInView = true;
}
}
private void _OnInputPaneHiding(object sender, IInputPaneVisibilityEventArgs eventArgs)
{
if (_ResetToDefaultElements())
{
eventArgs.EnsuredFocusedElementInView = true;
}
}
private void _StartElementRemovalAnimations()
{
// This function starts the process of removing elements
// and starting the animation.
}
private void _ResetToDefaultElements()
{
// This function resets the window's elements to their default state.
}
}
您引用的文章适用于 Windows 运行时应用程序,但它有一个小错误。 InputPane is in Windows.UI.ViewManagement 不在 Windows.Foundation.Application。更改它,其余的应该可以正常工作。
我已经报告了文档错误,因此可以修复它。
找到答案,报名那些活动就够了:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
InputPane.GetForCurrentView().Showing += onKeyboardShowing;
InputPane.GetForCurrentView().Hiding += onKeyboardHidding;
}
private void onKeyboardShowing(InputPane sender, InputPaneVisibilityEventArgs args)
{
KeyboardVisible = true;
}
private void onKeyboardHidding(InputPane sender, InputPaneVisibilityEventArgs args)
{
KeyboardVisible = false;
}