views:

94

answers:

1

push

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'm facing. 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"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
    <XmlDataProvider x:Key="XData1" XPath="/Info">
        <x:XData>
            <Info xmlns="">
                <Item>def</Item>
                <Item>efg</Item>
            </Info>
        </x:XData>
    </XmlDataProvider>

    <CollectionViewSource x:Key='Data1' Source="{Binding Source={StaticResource XData1}, XPath=Item}" />

</Window.Resources>
<Grid>
    <ComboBox IsEditable="True" IsTextSearchEnabled="True" Margin="0,0,0,283">
        <ComboBox.ItemsSource>
            <CompositeCollection>
                <ComboBoxItem>abc</ComboBoxItem>
                <ComboBoxItem>bcd</ComboBoxItem>
                <ComboBoxItem>cde</ComboBoxItem>
                <CollectionContainer Collection="{Binding Source={StaticResource Data1}}" />
            </CompositeCollection>

        </ComboBox.ItemsSource>
    </ComboBox>
</Grid>

Thanks! - dartrax

+1  A: 

I've found out that this is solved as soon as you override the ToString()-Function of your Items-object, so that it returns what the items DataTemplate shows.

A complete working example is here: --------> X

  • dartrax
dartrax