C#SilverLight。 Tab键不会更改文本框的焦点

时间:2016-03-17 08:39:23

标签: c# .net xaml silverlight

我有一点问题。

我将ListBox控件与文本框一起使用。

我将焦点设置在第一个文本框上,并尝试通过键选项卡跳转到以下文本框。 它不起作用。

我错了什么?

提前致谢!

<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; }
    }
}

1 个答案:

答案 0 :(得分:1)

您需要在样式中指定标签的工作方式。您不需要绑定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>