2016-02-03 23 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

谢谢,抱歉延误。你的答案对我有帮助。再次感谢你! –