1
Vote

Autocomplete textbox dropdown always shows when two way binding

description

When I navigate to a page with the autocomplete dropbox with two-way binding enabled, the dropdown always activates without user intervention.
 
Even setting IsDropDownOpen = false; in OnNavigatedTo doesn't stop it (probably to early, I should do it after the databind somehow).
 
This can be easily reproduced with the sample project by adding
<toolkit:AutoCompleteBox VerticalAlignment="Top" ItemsSource="{StaticResource words}" Text="{Binding Txt, Mode=TwoWay}" Margin="0,12"/>
 
And the following in the code behind:
public partial class AutoCompleteBoxSample : PhoneApplicationPage
{
    private static ACTextContext dc = new ACTextContext();
    public AutoCompleteBoxSample()
    {
        InitializeComponent();
        this.DataContext = dc;
    }
}
 
public class ACTextContext : INotifyPropertyChanged
{
    private string txt;
    public string Txt
    {
        get { return txt; }
        set { this.txt = value;
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("Txt"));
            }
        }
    }
 
    public event PropertyChangedEventHandler PropertyChanged;
}

comments

LittleColin wrote Mar 4, 2012 at 11:33 AM

It seems there is a workaround for this involving showing and hiding a text box:
http://forums.silverlight.net/t/230696.aspx/1?AutoCompleteBox+initial+value+in+Windows+Phone+7