- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我希望能够使用 return/enter 进入 UWP 应用程序中的下一个 TextBox
。 (我在这里包含了一个示例应用程序,但我的实际应用程序有很多行,所以我不想向每个 TextBox
添加一个 KeyDown
事件如果我能避免的话。)
我已将 KeyDown="Grid_KeyDown"
添加到我的 Grid
然后,如果用户按下 Enter,我将调用
FocusManager.TryMoveFocus(FocusNavigationDirection.Next)
它从第一个元素跳到第三个元素再到第五个。 Tab 在不跳过任何元素的情况下工作正常。
这是 XAML:
<Page
x:Class="CatApp.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:CatApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" KeyDown="Grid_KeyDown">
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0">First:</TextBlock>
<TextBlock Grid.Column="0" Grid.Row="1">Second:</TextBlock>
<TextBlock Grid.Column="0" Grid.Row="2">Third:</TextBlock>
<TextBlock Grid.Column="0" Grid.Row="3">Fourth:</TextBlock>
<TextBlock Grid.Column="0" Grid.Row="4">Fifth:</TextBlock>
<TextBlock Grid.Column="0" Grid.Row="5">Sixth:</TextBlock>
<TextBox Margin="10" Grid.Column="1" Grid.Row="0" TabIndex="1" ></TextBox>
<TextBox Margin="10" Grid.Column="1" Grid.Row="1" TabIndex="2" ></TextBox>
<TextBox Margin="10" Grid.Column="1" Grid.Row="2" TabIndex="3" ></TextBox>
<TextBox Margin="10" Grid.Column="1" Grid.Row="3" TabIndex="4" ></TextBox>
<TextBox Margin="10" Grid.Column="1" Grid.Row="4" TabIndex="5" ></TextBox>
<TextBox Margin="10" Grid.Column="1" Grid.Row="5" TabIndex="6" ></TextBox>
</Grid>
</Page>
下面是代码:
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
namespace CatApp
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void Grid_KeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.Enter)
{
FocusManager.TryMoveFocus(FocusNavigationDirection.Next);
}
}
}
}
最佳答案
这实际上是自 Windows 8 以来一直存在于 WinRT TextBox
中的一个已知错误,它似乎最终已在 Fall Creators Update (16299) 中得到修复。如果您的应用针对此版本的 Windows(或更高版本),它应该可以正常运行。
要查看发生了什么,请在事件处理程序中的 if
上放置一个断点。当您按下任意键时,处理程序将执行一次。但是当你按下 Enter 时,它实际上连续执行了两次,这导致你的焦点跳了两行。
修复非常简单 - 将事件标记为已处理就足够了:
private void Grid_KeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.Enter)
{
FocusManager.TryMoveFocus(FocusNavigationDirection.Next);
e.Handled = true;
}
}
这将防止处理程序执行两次,您的应用程序将按预期工作:-)。
关于c# - 使用 return/enter 而不是 tab 会跳过 UWP 应用程序中的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49131887/
询问 unrelated question我有这样的代码: public boolean equals(Object obj) { if (this == obj) retur
在我之前的一个问题中 js: Multiple return in Ternary Operator我询问了有关使用三元运算符返回多个参数的问题。但是现在参数IsActveUser boolean(t
假设我有一个带有 return 的 if 语句。从效率的角度来看,我应该使用 if(A > B): return A+1 return A-1 或 if(A > B): return
例如考虑以下代码: int main(int argc,char *argv[]) { int *p,*q; p = (int *)malloc(sizeof(int)*10); q
PyCharm 对这段代码发出警告,说最后一个返回是不可访问的: def foo(): with open(...): return 1 return 0 如果 ope
我想实现这样的目标: 如果在返回 Json 的方法中抛出异常,则返回 new Json(new { success = false, error = "unknown"}); 但如果方法返回 View
它是多余的,但我正在学习 JS,我想知道它是如何工作的。 直接从模块返回函数 let func1 = function () { let test = function () {
我不明白我应该使用什么。我有两页 - intro.jsp(1) 和 booksList.jsp(2)。我为每一页创建了一个 Controller 类。第一页有打开第二页的按钮:
我最近在 Joomla 组件(Kunena,更准确地说是 Kunena)中看到这段代码,那么使用 $this->return VS 简单的 return 语句有什么区别. 我已经用谷歌搜索了代码,但没
我的类实现了 IEnumerable。并且可以编译这两种方式来编写 GetEnumerator 方法: public IEnumerator GetEnumerator() { yield r
我只是在编码,我想到了一个简单的想法(显然是问题),如果我有一个像这样的函数: int fun1(int p){ return(p); } 我有一个这样的函数: int fun1(int p){
这个问题在这里已经有了答案: What does the comma operator do in JavaScript? (5 个答案) 关闭 9 年前。 function makeArray
假设我写了一个 for 循环,它将输出所有数字 1 到 x: x=4 for number in xrange(1,x+1): print number, #Output: 1 2 3 4 现
我最近在这个 Apache Axis tutorial example. 中看到了下面的一段代码 int main() { int status = AXIS2_SUCCESS; ax
function a(){ return{ bb:"a" } } and function a(){ return { bb:"a" } } 这两个代码有什么区别吗,如果有请
function a() { return 1; } function b() { return(1); } 我在 Chrome 的控制台中测试了上面的代码,都返回了 1。 function c()
考虑这三个函数: def my_func1(): print "Hello World" return None def my_func2(): print "Hello World"
这可能是一个愚蠢的问题,但我正在努力,如果有一种简明的方法来测试函数的返回结果,如果它不满足条件,则返回该值(即,传递它)。。现在来回答一个可能的问题,是的,我正在寻找的类似于例外提供的东西。然而,作
我正在测试一个函数,并尝试使用 return 来做什么,并在 PowerShell 5.1 和 PwSh 7.1 中偶然发现了一个奇怪的问题,即 return cmdlet似乎不适合在团体中工作: P
这个问题已经有答案了: Return in generator together with yield (2 个回答) Why can't I use yield with return? (5 个回
我是一名优秀的程序员,十分优秀!