对于 Windows Phone,当设备进入横向模式时,我是否可以注册一个事件?
我之所以问这个问题是因为我们有一个带有输入框的视图。当处于横向模式时,TextBox
部分被键盘阻挡。所以我想当页面处于横向模式时可能必须隐藏页面上的一些附加信息(例如,隐藏页面标题等)。
下面是一个简单的例子。
左:键盘显示之前;右:显示键盘后。
我发布了另一个与此相关的问题,并且就我而言有更好的解决方案:
为什么 ContentDialog 中的 TextBox 不自动滚动到键盘上方
但无论如何,这里是方向改变事件的完整代码:
// Define this in the class
private SimpleOrientationSensor _simpleorientation;
// Put hits in the Constructor
_simpleorientation = SimpleOrientationSensor.GetDefault();
if (_simpleorientation != null)
{
_simpleorientation.OrientationChanged += new TypedEventHandler<SimpleOrientationSensor, SimpleOrientationSensorOrientationChangedEventArgs>(OrientationChanged);
}
// Event function
private void OrientationChanged(object sender, SimpleOrientationSensorOrientationChangedEventArgs e)
{
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
// ...
});
}
你最好的选择是描述Windows.Current.SizeChanged
事件并测试宽度是否大于高度。还有一个传感器可以做到这一点,但有点问题,看看http://www.jayway.com/2014/10/06/detecting-orientation-in-universal-apps-windows-phone-8-1/.
.xaml
<ContentDialog
x:Class="App1.ContentDialog1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
SizeChanged="SizeChangedEvent">
<--! Other Code -->
</ContentDialog>
.cs
private void SizeChangedEvent(object sender, SizeChangedEventArgs e)
{
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)