How to TAB through TextBoxes in a ListView(如何在 ListView 中通过文本框进行 TAB)
问题描述
好的,我有一个 ListView,它有 2 个 GridViewColumns,一个显示一个数字,一个包含一个 TextBox我的问题是我希望能够通过 GridViewColumn 中的所有 TextBox 进行 Tab.使用附加的 Property KeyboardNavigation.TabNavigation,我几乎实现了我想要的.
我实现的是:
第一个 TAB - 整个第一个 ListViewItem 集中
第二个 TAB - 第一个 TextBox 聚焦
第三个 TAB - 整个第二个 ListViewItem 聚焦
第四个 TAB - 第二个 TextBox 聚焦
Ok I have a ListView that has 2 GridViewColumns one displaying a number and one containing a TextBox
My Problem is I want to be able to Tab through all the TextBoxes I have in the GridViewColumn.
With the attached Property KeyboardNavigation.TabNavigation I achieve almost what i want.
What i achieve is :
first TAB - whole first ListViewItem focused
second TAB - first TextBox focused
third TAB - whole second ListViewItem focused
fourth TAB - second TextBox focused
我想要的是
第一个 TAB - 第一个 TextBox 焦点
第二个 TAB - 第二个 TextBox 聚焦
<ListView KeyboardNavigation.TabNavigation="Continue" Name="TheLabelListView" >
<ListView.ItemContainerStyle >
<EventSetter Event="Selected" Handler="ItemSelected" /></Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView x:Name="GridViewSmall" >
<GridViewColumn Header="#" Width="20" DisplayMemberBinding="{Binding SelectorIndexNumber}" />
<GridViewColumn Header="Selector" Width="175">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Name="SelectorTextBox" Text="{Binding SelectorName}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
此代码是 H.B. 给我的..它应该在选择 ListViewÍtem 并找到 TextBox 并将其聚焦时执行.不知何故,它仍然不会每次都选择 TextBox,尽管执行此方法时 bool TextBoxgotFocus 始终为 true.
This code was given to me by H.B. . It is supposed to execute when a ListViewÍtem is selected and finds the TextBox and focuses it. Somehow it still doesnt select the TextBox everytime allthough when this method is executed bool TextBoxgotFocus is always true.
private void ItemSelected(object sender, RoutedEventArgs e)
{
var item = sender as ListViewItem;
TextBox h = (FindNamedChild(item, "SelectorTextBox") as TextBox);
bool TextBoxgotFocus = h.Focus();
}
public static object FindNamedChild(DependencyObject container, string name)
{
if (container is FrameworkElement)
{
if ((container as FrameworkElement).Name == name) return container;
}
var ccount = VisualTreeHelper.GetChildrenCount(container);
for (int i = 0; i < ccount; i++)
{
var child = VisualTreeHelper.GetChild(container, i);
var target = FindNamedChild(child, name);
if (target != null)
{
return target;
}
}
return null;
}
推荐答案
问题是对于列表视图中的每个项目,您有两个制表位:项目本身和文本框.您希望将项目本身的 KeyboardNavigation.IsTabStop
设置为 false
.只需将其设置为您的项目样式即可.
The problem is that for each item in the list view, you have two tab stops: the item itself and the text box. You want to set KeyboardNavigation.IsTabStop
to false
for the items themselves. Just set that in your item's style.
<ListView KeyboardNavigation.TabNavigation="Continue" Name="TheLabelListView">
<ListView.ItemContainerStyle>
<Style>
<Setter Property="KeyboardNavigation.IsTabStop" Value="False" />
</Style>
</ListView.ItemContainerStyle>
<!-- etc... -->
</ListView>
这篇关于如何在 ListView 中通过文本框进行 TAB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 ListView 中通过文本框进行 TAB
基础教程推荐
- rabbitmq 的 REST API 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- c# Math.Sqrt 实现 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 如何激活MC67中的红灯 2022-01-01