IsTabStop = False in the SL4 text field

I set IsTabStop to false in the text box, and I know that this makes the control unable to get focus, but according to the Silverlight Forums , it should still receive mouse events. I have a MouseLeftButtonUp event and a breakpoint in my tbxTotal_MouseLeftButtonUp method, and it never gets caught during debugging. The topic on the SL forums is already quite old, so maybe this has been changed in the update somewhere. I want a text box on which you cannot insert a tab, but is still editable. Should it be so hard?

+6
source share
2 answers

I did not realize this, but it seems to be so. Also, I cannot start MouseLeftButtonUp. MouseLeftButtonDown fires, although using this you can do this hack.

<TextBox IsTabStop="False" MouseLeftButtonDown="TextBox_MouseLeftButtonDown" /> 

Then in code, you can handle an 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 wrapping it in a CustomControl

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

@seekerOfKnowledge: Disabling IsTabStop in LostFocus is a good approach, but your repeated hack focus is not needed. It does not have a visible effect for the first time because the IsTabStop change has not yet IsTabStop effect. This approach can also be applied with any other control.

  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 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; }; } 
+1
source

Source: https://habr.com/ru/post/886708/


All Articles