title: How to group items inside custom control combobox?
body: <p>I've been trying to group the items of my custom control combobox using xaml and I'm a little stuck. I've been reading around and found the following code that produces the results I want, but I'd like to move all the code into the GroupedImageComboBox control.</p>
  
  <pre><code>&lt;StackPanel&gt;
  
          &lt;StackPanel.Resources&gt;
              &lt;CollectionViewSource x:Key="groupedData" Source="{Binding Items}"&gt;
                  &lt;CollectionViewSource.GroupDescriptions&gt;
                      &lt;PropertyGroupDescription PropertyName="EntityBaseDependencyType" Converter="{StaticResource enumConverter}"/&gt;
                  &lt;/CollectionViewSource.GroupDescriptions&gt;
              &lt;/CollectionViewSource&gt;
          &lt;/StackPanel.Resources&gt;
          &lt;WPFControls:GroupedImageComboBox  
                                           ItemsSource ="{Binding Source={StaticResource groupedData}}"     
                                            SelectedItem="{Binding SelectedItem}" 
                                        &gt;
              &lt;ItemsControl.GroupStyle&gt;
                  &lt;x:Static Member="GroupStyle.Default"/&gt;
              &lt;/ItemsControl.GroupStyle&gt;
          &lt;/WPFControls:GroupedImageComboBox&gt;
  
      &lt;/StackPanel&gt;
  </code></pre>
  
  <p>I would like to be able to remove the use of the stackpanel and the itemscontrol from this area and put them inside the GroupedImageComboBox. Is there a way to achieve this?</p>
  
  <p>Thanks in advance.</p>
  
  <p>Edit 1.</p>
  
  <p>I've been playing with the template and feel that I should be able to do the collectionview manipulations within the DropDown grid - I'm just not sure how....</p>
  
  <pre><code>&lt;Style TargetType="{x:Type WPFControls:ImageComboBox}"&gt;
      &lt;Setter Property="SnapsToDevicePixels" Value="true"/&gt;
      &lt;Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/&gt;
      &lt;Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/&gt;
      &lt;Setter Property="ScrollViewer.CanContentScroll" Value="true"/&gt;
      &lt;Setter Property="MinWidth" Value="120"/&gt;
      &lt;Setter Property="MinHeight" Value="20"/&gt;
      &lt;Setter Property="ItemContainerStyle" Value="{StaticResource CustomComboBoxItemStyle}"/&gt;
      &lt;Setter Property="IsSynchronizedWithCurrentItem" Value="true"/&gt;
      &lt;Setter Property="Margin" Value="8"/&gt;
      &lt;Setter Property="IsEditable" Value="False"/&gt;
      &lt;Setter Property="Template"&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate TargetType="ComboBox"&gt;
                  &lt;Grid&gt;                        
                      &lt;ToggleButton Name="ToggleButton" 
                                    Template="{StaticResource ComboBoxToggleButton}" 
                                    Grid.Column="2" 
                                    Focusable="false"
                                    IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
                                    ClickMode="Press"&gt;
                      &lt;/ToggleButton&gt;
                      &lt;ContentPresenter Name="ContentSite"
                                        IsHitTestVisible="False" 
                                        Content="{TemplateBinding SelectionBoxItem}"
                                        ContentTemplate="{StaticResource DiplayImageWithTextDataTemplate}"
                                        ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                                        Margin="3,3,23,3"
                                        VerticalAlignment="Center"
                                        HorizontalAlignment="Left" 
                                        /&gt;
                      &lt;TextBox x:Name="PART_EditableTextBox"              
                               Style="{x:Null}" 
                               Template="{StaticResource ComboBoxTextBox}" 
                               HorizontalAlignment="Left" 
                               VerticalAlignment="Center" 
                               Margin="3,3,23,3"
                               Focusable="True" 
                               Background="Transparent"
                               Visibility="Hidden"
                               IsReadOnly="{TemplateBinding IsReadOnly}"/&gt;
                      &lt;Popup Name="Popup"
                             Placement="Bottom"
                             IsOpen="{TemplateBinding IsDropDownOpen}"
                             AllowsTransparency="True" 
                             Focusable="False"
                             PopupAnimation="Slide"
                             &gt;
                          &lt;Grid Name="DropDown"
                                SnapsToDevicePixels="True"                
                                MinWidth="{TemplateBinding ActualWidth}"
                                MaxHeight="{TemplateBinding MaxDropDownHeight}"
                                &gt;
                              &lt;Border x:Name="DropDownBorder"
                                      Background="{StaticResource WindowBackgroundBrush}"
                                      BorderThickness="1"
                                      BorderBrush="{StaticResource SolidBorderBrush}"/&gt;
                              &lt;ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="True"&gt;
                                  &lt;ItemsPresenter KeyboardNavigation.DirectionalNavigation="Contained"
                                                  /&gt;
                              &lt;/ScrollViewer&gt;
                          &lt;/Grid&gt;
                      &lt;/Popup&gt;
                  &lt;/Grid&gt;
                  &lt;ControlTemplate.Triggers&gt;
                      &lt;Trigger Property="HasItems" Value="false"&gt;
                          &lt;Setter TargetName="DropDownBorder" Property="MinHeight" Value="95"/&gt;
                      &lt;/Trigger&gt;
                      &lt;Trigger Property="IsEnabled" Value="false"&gt;
                          &lt;Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/&gt;
                      &lt;/Trigger&gt;
                      &lt;Trigger Property="IsGrouping" Value="true"&gt;
                          &lt;Setter Property="ScrollViewer.CanContentScroll" Value="false"/&gt;
                      &lt;/Trigger&gt;
                      &lt;Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="true"&gt;
                          &lt;Setter TargetName="DropDownBorder" Property="CornerRadius" Value="4"/&gt;
                          &lt;Setter TargetName="DropDownBorder" Property="Margin" Value="0,2,0,0"/&gt;
                      &lt;/Trigger&gt;
                      &lt;Trigger Property="IsEditable" Value="true"&gt;
                          &lt;Setter Property="IsTabStop" Value="false"/&gt;
                          &lt;Setter TargetName="PART_EditableTextBox" Property="Visibility" Value="Visible"/&gt;
                          &lt;Setter TargetName="ContentSite" Property="Visibility" Value="Hidden"/&gt;
                      &lt;/Trigger&gt;
                  &lt;/ControlTemplate.Triggers&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
      &lt;Style.Triggers&gt;
      &lt;/Style.Triggers&gt;
  &lt;/Style&gt;
  </code></pre>