IsTabStop = False on a SL4 Text box

后端 未结 2 456
谎友^
谎友^ 2021-01-12 18:00

I set IsTabStop to false on a text box and I know that this makes the control unable to receive focus, but according to the Silverlight Forums, it should still be able to re

2条回答
  •  粉色の甜心
    2021-01-12 18:19

    I didn't realize this, but it seems to be the case, Additionally, I can't seem to get MouseLeftButtonUp to fire. MouseLeftButtonDown does fire though and using that you can do this hack.

    
    

    Then in code you can handle the event like this.

        private void TextBox_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var textBox = ((TextBox) sender);
            textBox.IsTabStop = true;
            textBox.Focus();
            textBox.IsTabStop = false;
        }
    

    It might be worth while to wrap it in a CustomControl

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

提交回复
热议问题