0

This is basically a follow up question to my previous question found here

I'm trying to group items in a combobox but my problem is that either the GroupDescription is shown or the items.

If I add collectionView.GroupDescriptions.Add(new PropertyGroupDescription("Team")); then my ComboBoxItem style will be disregarded (it never gets to a breakpoint). Why is that?

I've checked the collectionView and it contais 3 groups with 2 items in each as it should. But the dropdown only shows the "grouping name" (i.e. team name).

******EDIT******

The problem seems to be in my ComboBoxStyle since removing it makes life wonderful...

<Style x:Key="ImageComboBox" BasedOn="{StaticResource {x:Type ComboBox}}" TargetType="{x:Type ComboBox}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ComboBox">
                    <Grid>
                        <ToggleButton Name="ToggleButton" Template="{StaticResource ComboBoxToggleButton}" Grid.Column="2" Focusable="false" IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press"/>
                        <ContentPresenter Name="ContentSite" IsHitTestVisible="False" Content="{TemplateBinding SelectionBoxItem}" ContentTemplate="{StaticResource DisplayImageWithText}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" Margin="3,3,23,3" VerticalAlignment="Center" HorizontalAlignment="Left"/>
                        <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}"/>
                        <Popup Name="Popup" Placement="Bottom" IsOpen="{TemplateBinding IsDropDownOpen}" AllowsTransparency="True" Focusable="False" PopupAnimation="Slide">
                            <Grid Name="DropDown" SnapsToDevicePixels="True" MinWidth="{TemplateBinding ActualWidth}" MaxHeight="{TemplateBinding MaxDropDownHeight}">
                                <Border x:Name="DropDownBorder" Background="{StaticResource WindowBackgroundBrush}" BorderThickness="1" BorderBrush="{StaticResource SolidBorderBrush}"/>
                                <ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="True">
                                    <Grid x:Name="itemsGrid" Height="Auto" Width="Auto" MaxWidth="{TemplateBinding MaxWidth}">
                                        <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained"/>
                                    </Grid>
                                </ScrollViewer>
                            </Grid>
                        </Popup>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="HasItems" Value="false">
                            <Setter TargetName="DropDownBorder" Property="MinHeight" Value="95"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
                        </Trigger>
                        <Trigger Property="IsGrouping" Value="true">
                            <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
                        </Trigger>
                        <Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="true">
                            <Setter TargetName="DropDownBorder" Property="CornerRadius" Value="4"/>
                            <Setter TargetName="DropDownBorder" Property="Margin" Value="0,2,0,0"/>
                        </Trigger>
                        <Trigger Property="IsEditable" Value="true">
                            <Setter Property="IsTabStop" Value="false"/>
                            <Setter TargetName="PART_EditableTextBox" Property="Visibility" Value="Visible"/>
                            <Setter TargetName="ContentSite" Property="Visibility" Value="Hidden"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
Community
  • 1
  • 1
debe
  • 608
  • 1
  • 5
  • 13
  • Did you specify an ItemTemplate for the Items? – ASanch Aug 30 '10 at 15:08
  • In the ComboBoxItemStyle i have ... – debe Aug 30 '10 at 15:22
  • See my answer below. Hope it helps. If it doesn't help you solve the problem, maybe you can post more information on your question such as the XAML for the "ComboBoxItemStyle", and maybe the complete XAML for your ComboBox instance. – ASanch Aug 30 '10 at 15:36

1 Answers1

1

I'm not sure what's causing your problems based on the information you provided above. But the code below, which is an update to the answer I gave on the link you specified, works fine for me:

Styles:

<Style x:Key="ComboBoxItemStyle" TargetType="ComboBoxItem">
    <Setter Property="Foreground" Value="Red"/>
</Style>

<Style x:Key="ComboBoxStyle" BasedOn="{StaticResource {x:Type ComboBox}}" TargetType="{x:Type ComboBox}">
    <Setter Property="ItemContainerStyle" Value="{StaticResource ComboBoxItemStyle}"/>
</Style>

ComboBox:

<ComboBox x:Name="comboBox" Style="{StaticResource ComboBoxStyle}">
    <ComboBox.GroupStyle>
        <GroupStyle>
            <GroupStyle.HeaderTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Name}"/>
                </DataTemplate>
            </GroupStyle.HeaderTemplate>
        </GroupStyle>
    </ComboBox.GroupStyle>
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Name}"/>
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>

Hope this will help you solve your problem.

ASanch
  • 10,233
  • 46
  • 32
  • Your answer and comment made make some changes and it is the ComboBoxStyle that its the villain... updated the question with the complete style code – debe Aug 30 '10 at 16:07
  • I see, in your ComboBoxStyle, change the to an . I bet this should fix it. Let me know if it does. =) – ASanch Aug 30 '10 at 16:36
  • worked like a charm. Is it always supposed to be an ItemsPresenter at the lowest level or? – debe Aug 30 '10 at 18:53
  • Not necessarily. But normally, the ItemsPresenter should be used. This will ensure that even Groups will work. See this link for more info: http://social.msdn.microsoft.com/forums/en-US/wpf/thread/7b76d054-3570-444d-985f-f88aef532ad8/. – ASanch Aug 30 '10 at 19:01