在这种情况下如何控制 Tab 键顺序而不禁用控件的所有焦点

发布于 2024-12-06 06:28:14 字数 607 浏览 1 评论 0原文

我有一个看起来像这样的控件,它有几个文本框

[1 ][2 ][3 ][4 ]

现在在我的应用程序中这些控件正在形成某种矩阵,例如

[1 ][2 ][3 ][4 ]
[1 ][2 ][3 ][4 ]
[1 ][2 ][3 ][4 ]

现在我想设置 1 3 和 4 IsTabStop = false 以便用户可以仅通过选项卡浏览第二个文本框。 完成后我发现 1 3 4 现在无法聚焦。令我惊讶的是,在 WPF 中事实并非如此,因此这只是 Silverlight 的另一个意外限制!

http:// msdn.microsoft.com/ru-ru/library/system.windows.controls.control.istabstop(v=vs.95).aspx

如何继续通过 [2 进行初始 Tab 键操作] 计划?

I got a control that looks like this , it has several text boxes

[1 ][2 ][3 ][4 ]

Now in my app those controls are forming a somekind of a matrix like

[1 ][2 ][3 ][4 ]
[1 ][2 ][3 ][4 ]
[1 ][2 ][3 ][4 ]

Now I wanted to set 1 3 and 4 IsTabStop = false so user can tab through 2nd textboxes only.
After I have done that I found out that 1 3 4 now cannot be focused. And to my surprise in WPF this is not true, so its just another Silverlight unexpected limitation!

http://msdn.microsoft.com/ru-ru/library/system.windows.controls.control.istabstop(v=vs.95).aspx

How to proceed with my initial tabbing through [2 ] plan?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抹茶夏天i‖ 2024-12-13 06:28:14

我相信您可以扩展 TextBox 控件以使其可聚焦。请参阅这篇文章

附加属性

public class Ex
{
    public static bool GetIsTabStop(DependencyObject obj)
    {
        return (bool)obj.GetValue(IsTabStopProperty);
    }

    public static void SetIsTabStop(DependencyObject obj, bool value)
    {
        obj.SetValue(IsTabStopProperty, value);
    }

    // Using a DependencyProperty as the backing store for IsTabStop.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty IsTabStopProperty =
        DependencyProperty.RegisterAttached("IsTabStop", typeof(bool), typeof(Ex), new PropertyMetadata(true, Callback));

    private static void Callback(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        var control = d as Control;
        if (control != null)
        {
            control.IsTabStop = (bool)e.NewValue;

            control.MouseLeftButtonDown += (sender, args) =>
            {
                if (!control.IsTabStop)
                {
                    control.IsTabStop = true;
                    control.Focus();
                    control.IsTabStop = false;
                } 
            };
        }
    }
}

XAML

    <TextBox HorizontalAlignment="Left" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Margin="215,49,0,0" RenderTransformOrigin="0,7.25"/>
    <TextBox HorizontalAlignment="Left" local:Ex.IsTabStop="False" TextWrapping="Wrap" Text="TextBox" Margin="215,96,0,0" VerticalAlignment="Top"/>
    <RadioButton Content="RadioButton" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="210,144,0,0"/>
    <RadioButton Content="RadioButton" local:Ex.IsTabStop="False" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="213,183,0,0"/>

您基本上可以将其附加到从 Control 继承的任何内容。

I believe you can extend the TextBox control to have it focusable. See this post.

Attached Property

public class Ex
{
    public static bool GetIsTabStop(DependencyObject obj)
    {
        return (bool)obj.GetValue(IsTabStopProperty);
    }

    public static void SetIsTabStop(DependencyObject obj, bool value)
    {
        obj.SetValue(IsTabStopProperty, value);
    }

    // Using a DependencyProperty as the backing store for IsTabStop.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty IsTabStopProperty =
        DependencyProperty.RegisterAttached("IsTabStop", typeof(bool), typeof(Ex), new PropertyMetadata(true, Callback));

    private static void Callback(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        var control = d as Control;
        if (control != null)
        {
            control.IsTabStop = (bool)e.NewValue;

            control.MouseLeftButtonDown += (sender, args) =>
            {
                if (!control.IsTabStop)
                {
                    control.IsTabStop = true;
                    control.Focus();
                    control.IsTabStop = false;
                } 
            };
        }
    }
}

XAML

    <TextBox HorizontalAlignment="Left" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Margin="215,49,0,0" RenderTransformOrigin="0,7.25"/>
    <TextBox HorizontalAlignment="Left" local:Ex.IsTabStop="False" TextWrapping="Wrap" Text="TextBox" Margin="215,96,0,0" VerticalAlignment="Top"/>
    <RadioButton Content="RadioButton" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="210,144,0,0"/>
    <RadioButton Content="RadioButton" local:Ex.IsTabStop="False" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="213,183,0,0"/>

You can basically attach this to anything that's inherited from Control.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文