Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
3160
xamtexteditor valuechanged event puts cursor at beginning of text
posted

In the column below, the ValueChanged event is handled by tValueChanged. 

When XamTextEditor.Value is set, the cursor is positioned at the beginning of the text in the textbox.  This has the effect of causing the user to type in their text backwards.  So if i type "abc" I get "cba".  How do I fix this please?  I have already tried a value converter however the textbox is only updated after the user exit the field.  I want the value to be updated as the user types.

BTW the developer who originally wrote the code below claims it was working with version 11.2 and that it broke when the app was moved to 12.2.

 

<igDP:Field Name="BROKER" Label="Broker">
                    <igDP:Field.Settings>
                        <igDP:FieldSettings AllowEdit="True"
                                            CellClickAction="EnterEditModeIfAllowed"
                                            CellValuePresenterStyle="{StaticResource BrokerCell}">
                            <igDP:FieldSettings.EditorStyle>
                                <Style TargetType="{x:Type igEditors:XamTextEditor}"
                                       BasedOn="{StaticResource BaseTextEditorStyle}">
                                    <Setter Property="ValueConstraint">
                                        <Setter.Value>
                                            <igEditors:ValueConstraint MaxLength="3"/>
                                        </Setter.Value>
                                    </Setter>
                                    <EventSetter Event="ValueChanged" Handler="tValueChanged"/>
                                </Style>
                            </igDP:FieldSettings.EditorStyle>
                        </igDP:FieldSettings>
                    </igDP:Field.Settings>
                </igDP:Field>

 

private void tValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            var val = (string)e.NewValue;
            Dispatcher.BeginInvoke(new Action(() => ((XamTextEditor)sender).Value = val != null ? val.ToUpper() : val), DispatcherPriority.DataBind,null);
        }

 

  • 30945
    Verified Answer
    Offline posted

    Hello Sam,

     

    Thank you for your email. I have been looking into the behavior that you have described and I have managed to reproduce it in both version 11.2 and 12.2. In order to avoid this behavior, you can set the SelectionStart property of the XamTextEditor, to the Length of its text, which will cause the cursor to move to the last position and you will be able to type in the correct order. Also, since the code that you have provided is allowing input of three uppercase characters, as alternative, I can suggest using the XamMaskedInput and setting its Mask property to “>CCC”. The “>” sign will convert the following symbols to uppercase and the “C” indicates that character is allowed and it is not required. By using this mask you will be able to avoid handling the event and implementing the functionality there. Here is how this can be achieved:

     

    <igWPF:Field Name="department" Label="Department">

        <igWPF:Field.Settings>

            <igWPF:FieldSettings AllowEdit="True"

                                CellClickAction="EnterEditModeIfAllowed">

                <igWPF:FieldSettings.EditorStyle>

                    <Style TargetType="{x:Type igEdit:XamMaskedEditor}">

                        <Setter Property="Mask" Value=">CCC"/>                                      

                    </Style>

                </igWPF:FieldSettings.EditorStyle>

            </igWPF:FieldSettings>

        </igWPF:Field.Settings>

    </igWPF:Field>

     

    I have created a sample application, based on your code snippet, which shows how you can implement both of the approaches I have described.

     

    Please let me know if you need any further assistance on the matter.

     

    Sincerely,

    Krasimir

    Developer Support Engineer

    Infragistics

    www.infragistics.com/support

    TextEditorUppercaseTyping.zip