2016-02-03 26 views
0

我必須創建與圖片上相同的自定義列表框。帶有兩個分隔列的WPF列表框

enter image description here

我已經創造了在列表框中的每個項目增減的控制。但是我需要在列表框中有兩列,如果將是很多項目。如果它將是兩列,則它們必須按照圖片分開,並且每一列都應該有圓角的邊框。

代碼列表框低於:

<Style TargetType="{x:Type ListBox}" x:Key="ListBoxService"> 
     <Setter Property="ItemTemplate"> 
      <Setter.Value> 
       <DataTemplate DataType="{x:Type model:Service}"> 
        <Border 
         x:Name="border" 
         VerticalAlignment="Center" 
         BorderThickness="0, 0, 0, 2" 
         BorderBrush="{StaticResource CommonBackgroundColor}"> 
         <view:ServiceUpDown/> 
        </Border> 
       </DataTemplate> 
      </Setter.Value> 
     </Setter> 
     <Setter Property="ItemsPanel"> 
      <Setter.Value> 
       <ItemsPanelTemplate> 
        <UniformGrid Columns="2" HorizontalAlignment="Center"/> 
       </ItemsPanelTemplate> 
      </Setter.Value> 
     </Setter> 
     <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/> 
     <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled"/> 
    </Style> 

感謝您的幫助。

+0

你不能簡單地使用兩個列表框? – Usama

+0

如果我只有1-5件物品,那應該取決於物品的數量。 –

+0

使用轉換器時綁定itemsource – Usama

回答

0

不爲您的具體問題的解決方案,但也許這可以讓你開始:

<ListBox 
     ItemsSource="{Binding Items}" 
     ScrollViewer.VerticalScrollBarVisibility="Disabled" 
     > 
     <ListBox.ItemsPanel> 
      <ItemsPanelTemplate> 
       <WrapPanel Orientation="Vertical" /> 
      </ItemsPanelTemplate> 
     </ListBox.ItemsPanel> 

     <ListBox.ItemContainerStyle> 
      <Style TargetType="ListBoxItem"> 
       <Setter Property="Margin" 
      Value="0 0 20 0" /> 
      </Style> 
     </ListBox.ItemContainerStyle> 
    </ListBox> 

我已在ListBox的ItemsPanel設置爲垂直定向WrapPanel,所以一旦它填補了一個‘列’該列表框將它包裝到另一列中。 我已禁用ListBox的垂直滾動條,否則它將具有無限的垂直空間,因此WrapPanel將永遠不會換行。

一旦使用了ListBox的所有垂直空間,此示例將把這些項目包裝到附加列中。根據您的列表框的垂直大小和項目數量的不同,還可能需要第三列或第四列。您可以使用ItemContainerStyle分隔列,但這不能解決圓角邊框的要求。

+0

謝謝,抱歉延誤。你的答案對我有幫助。再次感謝你! –