CompositeCollection breaks ComboBox AutoComplete-Feature?
-
Thursday, February 25, 2010 9:12 AM
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" 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> </Window>Thanks!- dartrax
All Replies
-
Friday, February 26, 2010 10:41 AM*push*
-
Friday, February 26, 2010 11:40 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.
Thanks.
Sincerely.
Jim Zhou -MSFT -
Friday, February 26, 2010 2:39 PM
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 ;)(Bug reported here: http://wpf.codeplex.com/WorkItem/View.aspx?WorkItemId=11924)This is an example with makes it easy to compare the behavior of ComboBox and AutoCompleteBox when it comes to CompositeCollections:XAML:<Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit" 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 > </Window>Code-Behind:Partial Class MainWindow Public Sub New() InitializeComponent() 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

