In my WPF application, I have a UserControl that has two AutoCompleteBox controls in it. This UserControl can appear multiple times on a page. The problem is that when typing in AutoCompleteBox, the dropdown of choices doesn't appear. I'm handling the Populating event, and if I put a break point in there and step through, I can clearly see that the ItemsSource contains items in it, so it looks like it's working, except that I don't actually see the dropdown menu. I followed the code sample at http://msdn.microsoft.com/en-us/library/dd795156%28v=VS.95%29.aspx. What am I missing here?
XAML:
<my:AutoCompleteBox Name="acboxCoauthorName" Width="175" Unloaded="Control_Unloaded" MinimumPopulateDelay="100" Populating="acboxCoauthorName_Populating">
<my:AutoCompleteBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=LastOrCompanyName}"/>
</DataTemplate>
</my:AutoCompleteBox.ItemTemplate>
</my:AutoCompleteBox>
C#:
private void acboxCoauthorName_Populating(object sender, PopulatingEventArgs e)
{
e.Cancel = true;
var query = from a in _context.Authors
where a.Display_Name.StartsWith(acboxCoauthorName.Text)
select a;
acboxCoauthorName.ItemsSource = ((ObjectQuery) query).Execute(MergeOption.OverwriteChanges);
acboxCoauthorName.PopulateComplete();
}
While we're at it, I can't seem to databind the object that's in datacontext, either. I tried the databinding method above, or I went with the simpler:
<my:AutoCompleteBox Name="acboxCoauthorName" Width="175" MinimumPopulateDelay="100" Populating="acboxCoauthorName_Populating" Text="{Binding Path=LastOrCompanyName}">
Neither of those worked. Any ideas?
EDIT: Never mind on the second part; I had set the wrong object to be the control's DataContext.
Thanks.
If you are seeing things in the ItemSource, it should be okay...
Try setting the MinimumPrefixLength to 0 so that the popup shows even if no filtering is done so that you see what the list contains. Also make sure you set the Filter so you know what filter you're using.