2011-04-18 79 views
0

我一直在使用XAML想組我的自定義控制組合框的項目,我有點卡住了。我一直在閱讀,發現下面的代碼產生我想要的結果,但我想將所有代碼移到GroupedImageComboBox控件中。如何將自定義控件組合框內的項目分組?

<StackPanel> 

     <StackPanel.Resources> 
      <CollectionViewSource x:Key="groupedData" Source="{Binding Items}"> 
       <CollectionViewSource.GroupDescriptions> 
        <PropertyGroupDescription PropertyName="EntityBaseDependencyType" Converter="{StaticResource enumConverter}"/> 
       </CollectionViewSource.GroupDescriptions> 
      </CollectionViewSource> 
     </StackPanel.Resources> 
     <WPFControls:GroupedImageComboBox 
             ItemsSource ="{Binding Source={StaticResource groupedData}}"  
              SelectedItem="{Binding SelectedItem}" 
             > 
      <ItemsControl.GroupStyle> 
       <x:Static Member="GroupStyle.Default"/> 
      </ItemsControl.GroupStyle> 
     </WPFControls:GroupedImageComboBox> 

    </StackPanel> 

我希望能夠刪除使用StackPanel中,並從該領域的ItemsControl,並把他們的GroupedImageComboBox內。有沒有辦法做到這一點?

在此先感謝。

編輯1.

我一直在玩的模板,並認爲我應該可以下拉網格內做的CollectionView操作 - 我只是不知道如何....

<Style TargetType="{x:Type WPFControls:ImageComboBox}"> 
    <Setter Property="SnapsToDevicePixels" Value="true"/> 
    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/> 
    <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/> 
    <Setter Property="ScrollViewer.CanContentScroll" Value="true"/> 
    <Setter Property="MinWidth" Value="120"/> 
    <Setter Property="MinHeight" Value="20"/> 
    <Setter Property="ItemContainerStyle" Value="{StaticResource CustomComboBoxItemStyle}"/> 
    <Setter Property="IsSynchronizedWithCurrentItem" Value="true"/> 
    <Setter Property="Margin" Value="8"/> 
    <Setter Property="IsEditable" Value="False"/> 
    <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"> 
        </ToggleButton> 
        <ContentPresenter Name="ContentSite" 
             IsHitTestVisible="False" 
             Content="{TemplateBinding SelectionBoxItem}" 
             ContentTemplate="{StaticResource DiplayImageWithTextDataTemplate}" 
             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"> 
           <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Contained" 
               /> 
          </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.Triggers> 
    </Style.Triggers> 
</Style> 

回答

0

事實上,它似乎在這個例子中,堆面板不是你要使用的東西。

只需推動CollectionViewSource申報的其他地方(在你</Window.Resources><Window.Resources>標籤爲例),把你的組合框其他地方你想要的。

+0

我編輯的問題 - 我看到,這可以通過控制外部資源來解決,但我敢肯定,這是可能做到這裏面,我只是不知道如何! – user713169 2011-04-18 14:35:01

+0

嗯,我有點困惑在這裏...什麼是你的文章的編輯你想要做集合視圖源(即數據分組,據我瞭解:))之間有什麼聯繫?我有重讀您最初的問題,也許就是我在這裏失蹤的是「但我想將所有的代碼放到GroupedImageComboBox控制」的一部分... – Bruno 2011-04-18 21:00:43

相關問題