【问题标题】:C# SilverLight. The tab key does not change focus for the text boxesC#银光。 tab 键不会改变文本框的焦点
【发布时间】:2016-07-03 11:50:06
【问题描述】:

我有一个小问题。

我使用带有文本框的 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; }
    }
}

【问题讨论】:

    标签: c# .net xaml silverlight


    【解决方案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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多