2010-08-30 58 views
0

這基本上是一個跟進的問題我剛纔的問題中發現here分組項忽略的項目風格(組顯示空)

我想組項目中的組合框,但我的問題是,無論是GroupDescription是顯示或項目。

如果我添加collectionView.GroupDescriptions.Add(new PropertyGroupDescription("Team"));那麼我的ComboBoxItem樣式將被忽略(它永遠不會到達斷點)。這是爲什麼?

我檢查了collectionView,它包含3組,每組2個,因爲它應該。但下拉菜單僅顯示「分組名稱」(即團隊名稱)。

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

這個問題似乎是在我的ComboBoxStyle因爲除去它使生活更精彩......

<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> 
+0

您是否爲物品指定了ItemTemplate? – ASanch 2010-08-30 15:08:34

+0

在ComboBoxItemStyle我有 ... – debe 2010-08-30 15:22:28

+0

請參閱下面的答案。希望能幫助到你。如果它不能幫助你解決問題,也許你可以發佈更多關於你的問題的信息,例如「ComboBoxItemStyle」的XAML,以及可能是你的ComboBox實例的完整XAML。 – ASanch 2010-08-30 15:36:19

回答

1

我不知道根據您在上面提供的信息,導致您的問題的是什麼。但是,下面的代碼,這是一個更新,我給你指定的鏈路上的答案,工作正常,我:

樣式:

<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 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> 

希望這將幫助你解決你的問題。

+0

你的回答和評論作出了一些改變,它是ComboBoxStyle,它的惡棍......更新了問題的完整樣式代碼 – debe 2010-08-30 16:07:28

+0

我在你的ComboBoxStyle中看到,將更改爲。我敢打賭,這應該修復它。讓我知道如果它。 =) – ASanch 2010-08-30 16:36:00

+0

就像一個魅力。它總是應該是最低級別的ItemsPresenter還是? – debe 2010-08-30 18:53:24