Not using MoveFocusCharacters when text is selected

Editors for WPF Forum

Posted 8 years ago by John Dunn
Version: 10.1.0523
I've implemented an IP Address editor with a custom multipart editor. I've set the MoveFocusCharacters to ". " so if the user types in '' the editor will automatically jump to the next field. It also jumps to the next field when the user 'fills up' the current field. So if the user types '255255255255' they end up with '' which is what I would like. The problem is if the user both fills up a field and types the move focus character they get a double move - if the user types '' they end up getting ''.

The way that the Microsoft IP Address field deals with this ( as far as I can tell ) is that when the editor jumps to a new field it selects the text in the new field - my editor works like this as well. If text is selected it appears to ignore the move character. That allows for a user to type '' and end up with the correct value.

Is there a way to make my parts editor work in this fashion? I'm looking at the XAML for my Part template and I'm thinking I need to bind Part.MoveFocusCharacters to something in my MaskedTextBox with an appropriate converter but I'm not sure exactly how to accomplish what I need.

Comments (2)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Hi John,

You'd probably want to do something like:
<ControlTemplate ...>
    <editors:MaskedTextBox x:Name="PART_MaskedTextBox"... />
        <Trigger SourceName="PART_MaskedTextBox" Property="SelectionLength" Value="0">
            <Setter Property="MoveFocusCharacters" Value="." />
Alternatively, you could override the property metadata for the MoveFocusCharactersProperty and add a coerce callback, which would return null if editBox.MaskedTextBox.SelectionLength is not 0. Then you'd need to override OnApplyTemplate to attach to the MaskedTextBox.SelectionChanged event, and coerce MoveFocusCharactersProperty.

Actipro Software Support

Posted 8 years ago by John Dunn
Thanks, that worked perfectly.
The latest build of this product (v2018.1 build 0675) was released 11 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.