5

I have the following ComboBox in WPF. I know that I can add option ALL with CompositeCollection, but I don't know how. It would be great if somebody help me out with a short tutorial.

<ComboBox SelectionChanged="ComboBoxOperatingPoints_SelectionChanged" 
          x:Name="ComboBoxOperatingPoints" 
          DropDownOpened="ComboBoxOperatingPoints_DropDownOpened_1"
          FontSize="30" 
          HorizontalAlignment="Right" 
          Margin="40,40,0,0" 
          VerticalAlignment="Top" 
          Width="200" 
          Height="50"
          IsSynchronizedWithCurrentItem="True"
          ItemsSource="{Binding OperatingPoints}"
          DisplayMemberPath="name"
          SelectedValue="{Binding OperatingPointID,UpdateSourceTrigger=PropertyChanged,TargetNullValue=''}"
          SelectedValuePath="operating_point_id">
</ComboBox>
Anatoliy Nikolaev
  • 22,370
  • 15
  • 69
  • 68
Lóri Nóda
  • 694
  • 1
  • 10
  • 20
  • download this user control : http://www.codeproject.com/Articles/563862/Multi-Select-ComboBox-in-WPF – eran otzap Sep 07 '13 at 09:39
  • 1
    @eranotzap Sorry, I don't need to use a custom control for this job. As I know it's possible with a CompositeCollection and if there is a way to do this with it I would like to learn it. – Lóri Nóda Sep 07 '13 at 09:50

1 Answers1

8

Try this (msdn):

<ComboBox x:Name="ComboBoxOperatingPoints"  
          SelectionChanged="ComboBoxOperatingPoints_SelectionChanged" 
          Width="200" Height="50"
          IsSynchronizedWithCurrentItem="True"
          DisplayMemberPath="name"        
          SelectedValuePath="operating_point_id">
    <ComboBox.Resources>
        <CollectionViewSource x:Key="comboBoxSource" Source="{Binding Path=OperatingPoints}" />
    </ComboBox.Resources>
    <ComboBox.ItemsSource>
        <CompositeCollection>
            <local:OpPoint name="all" operating_point_id="-1" />
            <CollectionContainer Collection="{Binding Source={StaticResource comboBoxSource}}" />
        </CompositeCollection>
    </ComboBox.ItemsSource>
</ComboBox>
kmatyaszek
  • 19,016
  • 9
  • 60
  • 65