Silverlight SL4文本框上的IsTabStop=False

Silverlight SL4文本框上的IsTabStop=False,silverlight,silverlight-4.0,tabstop,Silverlight,Silverlight 4.0,Tabstop,我在文本框中将IsTabStop设置为false,我知道这会使控件无法接收焦点,但根据,它应该仍然能够接收鼠标事件。我在tbxTotal_MouseLeftButtonUp方法中连接了MouseLeftButtonUp事件和一个断点,并且在调试期间它从未被命中。SL论坛中的线程现在已经很旧了,所以可能在某个地方的更新中改变了。我想要一个文本框,它不能被标签,但仍然是可编辑的。真的应该这么难吗?我没有意识到这一点,但似乎是这样,此外,我似乎无法让MouseLeftButtonUp开火。MouseL

我在文本框中将IsTabStop设置为false,我知道这会使控件无法接收焦点,但根据,它应该仍然能够接收鼠标事件。我在tbxTotal_MouseLeftButtonUp方法中连接了MouseLeftButtonUp事件和一个断点,并且在调试期间它从未被命中。SL论坛中的线程现在已经很旧了,所以可能在某个地方的更新中改变了。我想要一个文本框,它不能被标签,但仍然是可编辑的。真的应该这么难吗?

我没有意识到这一点,但似乎是这样,此外,我似乎无法让MouseLeftButtonUp开火。MouseLeftButtonDown确实会开火,使用它你可以进行此攻击

<TextBox IsTabStop="False" MouseLeftButtonDown="TextBox_MouseLeftButtonDown" />
将其包装在CustomControl中可能是值得的

public class FocusableTextBox : TextBox
{
    protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
    {
        if (!IsTabStop)
        {
            IsTabStop = true;
            Focus();
            IsTabStop = false;
        }

        base.OnMouseLeftButtonDown(e);
    }
}

@seekerOfKnowledge:在
LostFocus
上禁用
IsTabStop
是一个很好的方法,但是您的重新聚焦黑客是不必要的。由于
IsTabStop
的更改尚未生效,因此在第一次使用时无法产生任何可见的效果。这种方法也可用于任何其他控制

        var control = sender as Control;
        if (control != null)
        {
            control.MouseLeftButtonDown += (sender, args) =>
                {   //This event fires even if the control isn't allowed focus. 
                    //As long as the control is visible, it's typically hit-testable.
                    if (!control.IsTabStop)
                    {
                        control.IsTabStop = true;
                        //threading required so IsTabStop change can take effect before assigning focus
                        control.Dispatcher.BeginInvoke(() =>
                            {
                                control.Focus();
                            });
                    }
                };

            control.LostFocus += (sender, args) =>
                {   //Remove IsTabStop once the user exits the control
                    control.IsTabStop = false;
                };
        }

嘿,我甚至没看到MouseLeftButtonDown是否有效。只是去证明假设是不好的。谢谢。但令人恼火的是,只是打电话。专注于MouseLeftButtonDown不起作用,这就是为什么你必须玩开/关舞蹈的原因:(另外,因为我的文本框位于树视图中,所以发生了一些奇怪的事情。当我单击文本框时,鼠标会被触发,我将IsTabStop设置为true,将其设置为焦点,在LostFocus中,我将IsTabStop设置为false。但是,文本框所在的树视图项会获得焦点,从而取消我刚才所做的操作。树视图项具有IsTabStop设置为false,所以我觉得它可以接收焦点很奇怪,但我也对此进行了尝试。在我的文本框LostFocus事件中,我实际上再次将焦点赋予文本框,然后直接将IsTabStop设置为false。@seekerOfKnowledge:非常感谢!
        var control = sender as Control;
        if (control != null)
        {
            control.MouseLeftButtonDown += (sender, args) =>
                {   //This event fires even if the control isn't allowed focus. 
                    //As long as the control is visible, it's typically hit-testable.
                    if (!control.IsTabStop)
                    {
                        control.IsTabStop = true;
                        //threading required so IsTabStop change can take effect before assigning focus
                        control.Dispatcher.BeginInvoke(() =>
                            {
                                control.Focus();
                            });
                    }
                };

            control.LostFocus += (sender, args) =>
                {   //Remove IsTabStop once the user exits the control
                    control.IsTabStop = false;
                };
        }