Search code examples
wpfdata-bindingtextboxtextchanged

Textbox.TextChanged triggering when page is loaded. How do I prevent it?


I am having trouble with textbox.textchanged event. my textboxes are data-bound and when the page is loaded, textchanged event triggers. How do I prevent it from happening and only trigger when the user makes any sort of changes?


Solution

  • Inside textchanged event handlers you can verify if window (or usercontrol, or whatever) is loaded:

    if (this.IsLoaded)
    {
       //your logic here
    }
    

    This way you can skip the first firing of TextChanged events, when the window is not loaded yet.