This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I am attempting to use the LostFocus event on the AutoCompleteBox. However, that event is called if a user clicks a selection in the drop down suggestion list before their selected value is copied to the textbox. In addition, I have not been able to find a way to see what item they clicked on in the collection to place it in the textbox myself. I was wondering if there was a better event I could use so that when the user either types something in or selects one of the options and then leaves the textbox I can process the value or if there is a way to find out what item the user clicked on even if it isn't copied to the textbox. Thanks for all your help! Andrew |
|
|
Hello Andrew Here is one way to work around this scenario to achieve the behaviour you have described: If you are setting the SuggestionSource to be a collection, then iterate through this collection in the LostFocus event handler. Check to see if the AutoCompleteBox.Text property matches one of the strings in the collection. If the text is found in the collection, then you can continue on with whatever logic you want with the text. If it is not found in the collection, then it will be the scenario where the user has clicked on an item and the LostFocus event is called before the text is set. Now your logic will only run when the user either types something in or selects one of the options and then leaves the text box. If you are using an IAutoCompleteSuggestionProvider, then you do the same as above, but iterate through the collection generated by the GetSuggestions method on the IAutoCompleteSuggestionProvider. Another approach would be to listen to the LostFocus event, and then run your logic through a dispatcher. That way, the AutoCompleteBox.Text property will be set before your logic gets hit. This will produce a slightly different behaviour than the approach above: In the scenario when the user clicks on a selection from the list, your logic will be executed straight away, rather than waiting for the AutoCompleteBox to lose focus again. Here is example code for using a dispatcher:
Let us know if these produce the desired behaviour. -Jason |
|