Autocompletebox.SearchText not clearing when datacontext changes

May 3, 2011 at 3:25 PM


I'm binding to the autocompletebox using MVVM.  When the datacontext changes however I find my autocompleteboxes will still contain the SearchText entered before the datacontext changed.  You cannot bind the SearchText  and you cannot set it by subclassing autocompletebox or attached behaviour.   Setting the Text property to null won't work either.

Right now I'm hacking it by reflecting and setting the SearchText to null :

       void AutoCompleteBoxDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
            SetPrivatePropertyValue<AutoCompleteBox>(this, t => t.SearchText, string.Empty);

It's pretty evil, but it needs to just work for me now.