WPF Toolkit AutoCompleteBox dropdown doesn't appear

2.8k views Asked by At

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.

2

There are 2 answers

0
Alex Florescu On

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.

0
mjhamre On

I'm pretty new to WPF and was having the same issue.

I was also following Microsoft's template for adding this control.

About an hour of searching later, a silverlight forum(http://forums.silverlight.net/t/178152.aspx/1) had the suggestion :

Try to add FilterMode="None" to XAML

Worked for me, maybe they changed the default value since the original example was written, or maybe someone who knows more about WPF and this particular control can clarify further (I was just glad to stop pulling my hair out).