Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to dismiss the dropdown list of an autocompletebox in windows phone 7
    text
    copied!<p>is there anyway to programmatically dismiss the drop-down list of an autocompletebox? my use case is as follows.</p> <p>MainPage.xaml passes a value to SearchPage.xaml (i.e. /SearchPage.xaml?query=someText).</p> <p>in SearchPage.xaml.cs, i set, </p> <pre><code>autoCompleteBox.Text = NavigationContext.QueryString["query"]. </code></pre> <p>at this point, the drop-down list of suggested matches shows up. i don't want this behavior when the page is just navigated to.</p> <p>i also tried the following to dismiss the drop-down list but it didn't help.</p> <pre><code>autoCompleteBox.Text = NavigationContext.QueryString["query"]; autoCompleteBox.IsDropDownOpen = false; </code></pre> <p>the drop-down list seems to go away from the AutoCompleteBox when it loses focuses, but i don't see a property/field to set to make it lose focus.</p> <p>any help is appreciated.</p> <p>well, i tinkered a bit and came up with a kludge. in the constructor of SearchPage.xaml.cs i have the following code.</p> <pre><code>autoCompleteBox.TextFilter += DummyFilter; autoCompleteBox.GotFocus += (s,args) =&gt; { if(!isAutoCompleteBoxInit) { autoCompleteBox.TextFilter -= DummyFilter; autoCompleteBox.TextFilter += RealFilter; } } </code></pre> <p>DummyFilter looks like the following.</p> <pre><code>bool DummyFilter(string search, string value) { return false; } </code></pre> <p>RealFilter looks like the following.</p> <pre><code>bool RealFilter(string search, string value) { if(null != value) return value.ToLower().StartsWith(search.ToLower()); } </code></pre> <p>in my OnNavigatedTo method, is where i set, autoCompleteBox.Text = NavigationContext.QueryString["query"]. so when i do this now, the DummyFilter will always return false, so the drop-down list goes away. when the user focuses in on the AutoCompleteBox, i check if the correct Filter was already attached to the TextFilter property, if not, then i do a switch.</p> <p>hope this helps some of you.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload