C#SilverLight。tab键不会更改文本框的焦点
我有个小问题 我对文本框使用ListBox控件 我将焦点设置在第一个文本框上,并尝试通过键选项卡跳到下面的文本框上。 它不起作用 我错了什么 提前谢谢C#SilverLight。tab键不会更改文本框的焦点,c#,.net,xaml,silverlight,C#,.net,Xaml,Silverlight,我有个小问题 我对文本框使用ListBox控件 我将焦点设置在第一个文本框上,并尝试通过键选项卡跳到下面的文本框上。 它不起作用 我错了什么 提前谢谢 <ListBox Name="Box" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Background="Transparent" BorderThickness="0"> <ListBox.ItemContainerStyle>
<ListBox Name="Box" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Background="Transparent" BorderThickness="0">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<StackPanel Orientation="Horizontal" Margin="40,2,0,2">
<TextBlock Text="{Binding Label}" MinWidth="20" />
<TextBox TabIndex="{Binding Index, Mode=OneWay}" Text="{Binding Information, Mode=TwoWay}"/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
namespace SilverlightApplication1
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
var model = new List<Model>()
{
new Model() {Index = 1, Label = "1"},
new Model() {Index = 2, Label = "2"},
new Model() {Index = 3, Label = "3"},
new Model() {Index = 4, Label = "4"}
};
Box.ItemsSource = model;
}
}
public class Model
{
public int Index { get; set; }
public string Label { get; set; }
public string Information { get; set; }
}
}
命名空间SilverlightApplication1
{
公共部分类主页面:UserControl
{
公共主页()
{
初始化组件();
var模型=新列表()
{
新模型(){Index=1,Label=“1”},
新模型(){Index=2,Label=“2”},
新模型(){Index=3,Label=“3”},
新模型(){Index=4,Label=“4”}
};
Box.ItemsSource=模型;
}
}
公共类模型
{
公共int索引{get;set;}
公共字符串标签{get;set;}
公共字符串信息{get;set;}
}
}
您需要在样式中指定选项卡的工作方式。您不需要绑定tabindex,除非您想更改选项卡的工作顺序。我认为这应该与您正在尝试的工作类似:
<ListBox Name="Box"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
Background="Transparent"
BorderThickness="0">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<StackPanel Orientation="Horizontal"
Margin="40,2,0,2">
<TextBlock Text="{Binding Label}"
MinWidth="20" />
<TextBox Text="{Binding Information, Mode=TwoWay}" />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="IsTabStop"
Value="False" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.Style>
<Style TargetType="ListBox">
<Setter Property="TabNavigation"
Value="Cycle" />
</Style>
</ListBox.Style>
</ListBox>