2013-05-10 46 views
0

ItemsControl我需要必須this appearance浮動ItemsControl的

enter image description here

對於ItemsPanel我已經設置了水平方向的StackPanel

<Style TargetType="local:ParameterItemContainer"> 
    <Setter Property="ItemsPanel"> 
     <Setter.Value> 
      <ItemsPanelTemplate> 
       <StackPanel Orientation="Horizontal"/> 
      </ItemsPanelTemplate> 
     </Setter.Value> 
    </Setter> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="local:ParameterItemContainer"> 
       <Border Background="{TemplateBinding Background}" 
         BorderBrush="{TemplateBinding BorderBrush}" 
         BorderThickness="{TemplateBinding BorderThickness}"> 
        <Grid > 
         <Grid.ColumnDefinitions> 
          <ColumnDefinition Width="Auto"/> 
         </Grid.ColumnDefinitions> 
         <Grid.RowDefinitions> 
          <RowDefinition/> 
          <RowDefinition/> 
          <RowDefinition/> 
          <RowDefinition/> 
          <RowDefinition/> 
          <RowDefinition/> 
         </Grid.RowDefinitions> 

         <ItemsPresenter Margin="{TemplateBinding Margin}" /> 
        </Grid> 
       </Border> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

ParameterItemContainer來自ItemsControl

不知道如何正確地實現模板以獲得與我的截圖相同的外觀,還是我必須重寫一個函數來設置正確的佈局?

+0

你有沒有嘗試用'Orientation =「Vertical」'將'ItemsPanelTemplate'設置爲'WrapPanel',並給它一個6x物品的高度? – Rachel 2013-05-10 13:51:30

+0

非常感謝,這是我的問題的答案。 – 2013-05-10 14:04:57

+0

好吧,我把它作爲答案發布在下面:)我不完全確定這是你根據你的問題標題尋找什麼,這就是爲什麼我發佈它作爲評論。 – Rachel 2013-05-10 14:10:13

回答

1

我不知道你"Floating ItemsControl"的意思,但如果你只是看在ItemsControl一次顯示的6個項目行可以設置ItemsPanelTemplateOrientation="Vertical"一個WrapPanel,並給它一個身高任何6x項目將是。

<ItemsPanelTemplate> 
    <WrapPanel Orientation="Vertical" Height="300" /> 
</ItemsPanelTemplate> 

這將WPF繪圖項目垂直,直到它達到高度限制,然後它將水平換行到一個新列以繼續繪製項目。