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
335
Preserve null value in XamTextEditor
posted

How can I convince XamTextEditor to preserve existing null value if user didn't change anything, instead of setting it to empty string on lost focus.

<igEditors:XamTextEditor Text="{Binding Value, UpdateSourceTrigger=LostFocus}" />

I've tried handling EditModeEnding event:

if (string.IsNullOrEmpty(editor.Text) && UnwrapNull(editor.OriginalValue) == null)
{
    e.Cancel = true;
}

But it still sets "" on binding source.

Also, I want to be able to set empty string if that is a result of user edit (eg. user selected everything and pressed backspace) so I can't use converter on binding to change "" into null and above method even if it worked wouldn't solve my problem completely.

Parents
  • 35319
    posted

    Hello,

     

    I have been looking into your question and if you would like to set the initial value of the ‘Text’ property of the XamTextEditor when the user types white spaces or does not change its default value, I can suggest you to store the initial value in a string variable and set it on the ‘EditModeEnding’ event if the above requirements are met like :

     

    string str;

     

     

      private void editor_EditModeEnding(object sender, Infragistics.Windows.Editors.Events.EditModeEndingEventArgs e)

            {

                if (string.IsNullOrWhiteSpace(editor.Text))

                {

                    editor.Text = str;

                }

            }

     

            private void editor_Loaded(object sender, RoutedEventArgs e)

            {

                str = editor.Text;

            }

     

    If I have misunderstood you in any way, please do not hesitate to tell me.

Reply Children