问题描述
好吧,我有一个具有2 GridViewColumns显示A的数字和一个包含一个文本框一个ListView
我的问题是我想通过我的一切在GridViewColumn文本框,以便能够标签。
随着附加属性KeyboardNavigation.TabNavigation我实现几乎我想要什么。结果
我所实现的是:结果
第一个标签 - 整个第一ListViewItem的重点结果
第二个选项卡 - 第一个TextBox关注结果
第三个选项卡 - 整个第二ListViewItem的重点结果
第四个选项卡 - 第二个文本框聚焦
我要的是结果
第一个标签 - 一个TextBox注重结果
第二个选项卡 - 第二个文本框聚焦
< ListView控件KeyboardNavigation.TabNavigation =继续NAME =TheLabelListView>
< ListView.ItemContainerStyle>
< EventSetter事件=选择处理器=ItemSelected/>< /样式和GT;
< /ListView.ItemContainerStyle>
< ListView.View>
< GridView的X:名称=GridViewSmall>
< GridViewColumn标题=#WIDTH =20DisplayMemberBinding ={结合SelectorIndexNumber}/>
< GridViewColumn头=选择WIDTH =175>
< GridViewColumn.CellTemplate>
<&DataTemplate的GT;
<文本框名称=SelectorTextBox文本={结合SelectorName}/>
< / DataTemplate中>
< /GridViewColumn.CellTemplate>
< / GridViewColumn>
< / GridView的>
< /ListView.View>
< /&的ListView GT;
这code被H.B.给我。它应该执行当选择一个ListViewItem的,发现文本框和重点吧。不知怎的,它仍犯规选中文本框每次allthough时执行此方法布尔TextBoxgotFocus始终为true。
私人无效ItemSelected(对象发件人,RoutedEventArgs E)
{
VAR项目=发件人作为ListViewItem的;
文本框H =(FindNamedChild(项目SelectorTextBox)作为文本框);
布尔TextBoxgotFocus = h.Focus();
} 公共静态对象FindNamedChild(DependencyObject的容器中,字符串名称)
{
如果(容器是FrameworkElement的)
{
如果((容器作为FrameworkElement的).Name点== name)返回容器中;
}
VAR ccount = VisualTreeHelper.GetChildrenCount(容器);
的for(int i = 0; I< ccount;我++)
{
VAR孩子= VisualTreeHelper.GetChild(集装箱,I);
VAR的目标= FindNamedChild(孩子名字);
如果(目标!= NULL)
{
返回的目标;
}
}
返回null;
}
的问题是,在列表视图中的每个项目,你有两个制表位:项目本身和文本框。你想设置 KeyboardNavigation.IsTabStop
到假
用于项目本身。只需设置,在您的项目的风采。
< ListView控件KeyboardNavigation.TabNavigation =继续NAME =TheLabelListView>
< ListView.ItemContainerStyle>
<样式和GT;
< setter属性=KeyboardNavigation.IsTabStopVALUE =FALSE/>
< /样式和GT;
< /ListView.ItemContainerStyle> <! - 等等...... - >
< /&的ListView GT;
Ok I have a ListView that has 2 GridViewColumns one displaying a number and one containing a TextBoxMy 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
What i want is
first TAB - first TextBox focused
second TAB - second TextBox focused
<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>
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;
}
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>
这篇关于如何通过TAB在ListView文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!