Not using MoveFocusCharacters when text is selected

Editors for WPF Forum

Posted 9 years ago by John Dunn
Version: 10.1.0523
Avatar
I've implemented an IP Address editor with a custom multipart editor. I've set the MoveFocusCharacters to ". " so if the user types in '1.2.3.4' 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 '255.255.255.255' 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 '255.255.255.255' they end up getting '255.0.255.0'.

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 '255.255.255.255' 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 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi John,

You'd probably want to do something like:
<ControlTemplate ...>
    <editors:MaskedTextBox x:Name="PART_MaskedTextBox"... />
    <ControlTemplate.Triggers>
        <Trigger SourceName="PART_MaskedTextBox" Property="SelectionLength" Value="0">
            <Setter Property="MoveFocusCharacters" Value="." />
        </Trigger>
    </ControlTemplate.Triggers>
</ControlTemplate>
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 9 years ago by John Dunn
Avatar
Thanks, that worked perfectly.
The latest build of this product (v2019.1 build 0681) was released 9 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.