Hello,
I have a search box which is a XamTextEditor. I set it's Null value to "search"
The problem is that when i am typing something in it, everything works. But when i try to clear the text (clear the last character in the textEditor or clear all of it), it isn't cleared and the last char is remained in the box.
I bind the TextEditor to a string property this way:
private string searchText; public string SearchText { set { if (searchText != value) { searchText = value; if (!string.IsNullOrEmpty(value)) { SearchAllViewModel.SetSearchText(searchText); } else { searchText = null; SearchAllViewModel.ClearSearchText(); } SendPropertyChanged(() => SearchText); } } get { return searchText; } }
If i remove the "else" code, it works and i am able to clear the box. but with "else" code i can't
Hello michaelgr1,
I am glad that you have managed to solve your issue.
Thank you for choosing Infragistics components.
Sincerely,
Ekaterina
Developer Support Engineer
Infragistics, Inc.
www.infragistics.com/support
OK i solved this.
Inside RemoveChildren i am publishing event using EventAggregator (PRISM). For some reason it caused the private member of the SearchViewModel to have the previous value when it is NULL. so i just call the EventAggregator once the _searchText is not null (eventually the event activates the XamContentPane which has the search results)
Hmmm , it doesn't help.
I changed my code to :
public string SearchText { set { SearchAllViewModel.SearchText = value; SendPropertyChanged(() => SearchText); } get { return SearchAllViewModel.SearchText; } }
The searchAllViewModel SearchText property code is:
private string _searchText; public string SearchText { set { if (!string.IsNullOrEmpty(value)) { if (_timer!=null && _searchText != value && _timer.IsEnabled) { _searchText = value; _timer.Stop(); _timer.Start(); } else if (_searchText != value) { _timer = new DispatcherTimer(new TimeSpan(0, 0, 0, 2), DispatcherPriority.DataBind, TimerElapsed, Dispatcher.CurrentDispatcher); _searchText = value; _timer.Start(); } } else { _searchText = value; RemoveChildren(); } } get { return _searchText; } }
I have been looking into your issue and using your code behind I have bound the xamTextEditor to the SearchText like that:
<igEditors:XamTextEditor Text="{Binding Source={StaticResource a}, Path=SearchText}" …/>
Please notice that I have not set the Mode property, so in case you have provided some value for that one, you can try removing it, or set it to TwoWay, because otherwise your setter would not be invoked.
I have comment out the :
SearchAllViewModel.SetSearchText(searchText);
SearchAllViewModel.ClearSearchText();
statements, because I do not have your ViewModel implementation. When I tested the application it worked as expected.
As you have pointed out, the execution is correct when you remove the “else part of the check”, and it seems that the issue is somewhere in the ClearSearchText implementation. Please notice that this method will be called only when the whole editors text has been removed –‘the deletion of the first char will cause the SetSearchText to set the new text (minus last char), than you will iterate through this step as long as there are characters in the editors text. When you delete the last character, you will go in the else statement and the ClearSearchText will be called. I am not sure what is the exact idea of this method, because the SetSearchText will anyway set an empty string to your data source.
This said, I am not able to determine any issue with your code, so I assume that there is something in your xaml, INotifyPropertyChanged implementation or with your ViewModel methods that causes the undesired behavior. In order for me to start investigation can you please provide me with some additional detail on the mentioned components or send isolated sample that demonstrates the issue.
I will be looking forward to hearing from you.