Set doubleditbox (and int32editbox) in edit mode when clicking on the white space

Editors for WPF Forum

Posted 4 years ago by Moondance
Version: 15.1.0624
Avatar

In my application I am using both doubleeditbox and int32editbox. The current default  behavior of these editors is that if the user clicks on the number or right at the very end of the number the editors are placed in edit mode. But if the user instead clicks on the white part of the editor (to the right of the number), the whole number gets selected. This behavior can be seen in the sample application as well.

I need to change the behavior so that if the user clicks on the white right part of the editor the text is not selected but the editor is placed in edit mode with the caret positioned at the end of the text. I have tried several things none of which worked. Can you prodide a style or a template to achieve this effect?

Thanks

Comments (3)

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

You might be able to override the edit box's OnMouseLeftButtonDown method.  Call the base method first and then do a hit test to see if the mouse was to the right of the TextBoxBase control in there.  If so, then change the selection properties on that TextBoxBase.


Actipro Software Support

Posted 4 years ago by Moondance
Avatar

Thank you. This got me almost there. The problem now is that when I click and drag (in order to select the text) the text does not get selected.

I have to do the operation twice to make it happen, and this after I override the OnMouseMove method.

Can you please take a look at this code and see what is missing?

I have a CustomDoubleEditBox that derives from DoubleEditBox.

The I override the following two methods:

protected override void OnMouseMove(MouseEventArgs e)
{
      base.OnMouseMove(e);
      if (e.LeftButton == MouseButtonState.Pressed)
      {
            MaskedBox.CaptureMouse();
            MaskedBox.InvalidateArrange();
      }
}

protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
      base.OnMouseLeftButtonDown(e);
      var uiElement = InputHitTest(e.GetPosition(this));
      if ((uiElement as Grid) == null)
      {
            MaskedBox.Focus();
            MaskedBox.SelectionLength = 0;
            MaskedBox.CaretIndex = MaskedBox.Text.Length;
     }
}

private MaskedTextBox MaskedBox

{
    get
    {
         return _maskedBox ?? (_maskedBox = (MaskedTextBox)VisualTreeHelperExtended.GetFirstDescendant(this,

         typeof(MaskedTextBox)));
    }
}

THank you very much

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

What you are trying to do with starting a selection unfortunately won't work with the current codebase.  There is an internal mouseSelectionActive field in TextBoxBase that gets set to true only in MaskedTextBox.OnMouseLeftButtonDown if the mouse is over the control.  Without that flag set, selection won't ever start.


Actipro Software Support

The latest build of this product (v2019.1 build 0683) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.