CompositeCollection breaks ComboBox AutoComplete-Feature?


  • Hello everybody!

    I'm using a WPF ComboBox with IsTextSearchEnabled="True" (Autocomplete) and want to bind its ItemsSource-Property to a CompositeCollection. Unfortunately, the Combobox doesn't seem to recognize the items provided by a CollectionContainer within the CompositeCollection. They are shown, but not selected by AutoComplete.

    Please try the example, type in "def". If "def" doesn't get selected, you've reproduced the problem I face. Is there any solution, something that I've overseen or a practical way to work around while having some mergedcollection-capability?

    <Window x:Class="MainWindow"
    Title="MainWindow" Height="350" Width="525">
        <XmlDataProvider x:Key="XData1" XPath="/Info">
                <Info xmlns="">
        <CollectionViewSource x:Key='Data1' Source="{Binding Source={StaticResource XData1}, XPath=Item}" />
        <ComboBox IsEditable="True" IsTextSearchEnabled="True" Margin="0,0,0,283">
                    <CollectionContainer Collection="{Binding Source={StaticResource Data1}}" />

    - dartrax
    Thursday, February 25, 2010 9:12 AM

All replies

  • *push*
    Friday, February 26, 2010 10:41 AM
  • Hi dartrax,

    It really looks like an issue. First, I thought it maybe caused by the XML data island, then I replace the XML data with a class named Person, which has one property of type string. But the result it's the same, I will look into it further. Anything new, I will let you know immediately.


    Jim Zhou -MSFT
    Friday, February 26, 2010 11:40 AM
  • Hi Jim,

    thanks for looking into that.

    I've played a bit around with the AutoCompleteBox that is shipped with the WPF Toolkit February 2010 Release. The result is, the ComboBox works with the CompositeCollection as long as the Items provide a ToString()-Method. In the end was able to solve/work around (?) my problem.

    However, the new AutoCompleteBox does NOT work with CompositeCollections (yet). You'll find the Items covered by a CollectionContainer by typing System.Windows.Data.CollectionContainer into it ;)

    This is an example with makes it easy to compare the behavior of ComboBox and AutoCompleteBox when it comes to CompositeCollections:

    <Window x:Class="MainWindow"
        Title="MainWindow" Height="350" Width="525">
        <StackPanel >
            <ComboBox x:Name="ComboBox" IsEditable="True"/>
            <toolkit:AutoCompleteBox x:Name="AutoCompleteBox" IsTextCompletionEnabled="True"/>
            <ListBox x:Name="ListBox"/>
        </StackPanel >
    Partial Class MainWindow
        Public Sub New()
            Dim CompositeCollection As New CompositeCollection From {New Item("1.0.0"), _
                                                                     New Item("2.0.0"), _
                                                                     New Item("3.0.0"), _
                                                                     New CollectionContainer With {.Collection = New CompositeCollection From {New Item("3.1.0"), _
                                                                                                                                               New Item("3.2.0"), _
                                                                                                                                               New Item("3.3.0"), _
                                                                                                                                               New CollectionContainer With {.Collection = New CompositeCollection From {New Item("3.3.1"), _
                                                                                                                                                                                                                         New Item("3.3.2"), _
                                                                                                                                                                                                                         New Item("3.3.3")}}}}}
            ListBox.ItemsSource = CompositeCollection
            ComboBox.ItemsSource = CompositeCollection
            AutoCompleteBox.ItemsSource = CompositeCollection
        End Sub
    End Class
    Public Class Item
        Dim Name As String
        Public Sub New(ByVal Name As String)
            Me.Name = Name
        End Sub
        Public Overrides Function ToString() As String
            Return Name
        End Function
    End Class
    - dartrax
    Friday, February 26, 2010 2:39 PM