2012-05-21 48 views
1

我想在列表框中有多个列,其中包含我通过从数据库获取值动态创建的复选框。代码是这样的:带多列的列表框

<StackPanel Width="250" Height="80"> 
<ListBox Name="listBoxZone" ItemsSource="{Binding TheList}" Height="115" Background="Azure"> 
<ListBox.ItemTemplate> 
    <DataTemplate> 
     <CheckBox Name="CheckBoxZone" Content="{Binding TheText}" Tag="{Binding TheValue}" Checked="CheckBoxZone_Checked" Margin="0,5,0,0"/> 
    </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 

但这里的复选框陆续来到一个水平......我想经过5个复选框更改列...我用画布面板在这里,但它把所有的复选框全部复选框垂直排列。

那么现在该怎么做?

+0

我不明白你的问题。你想要达到什么目的?什么意思是“我想改变5个复选框后的列” – csteinmueller

+0

@csteinmueller ..是的 –

回答

1

你应该试试这个:当达到控制的宽度边界,而不是项目数达到5

<ListBox Name="listBoxZone" ItemsSource="{Binding TheList}" Height="115" Background="Azure"> 
    <ListBox.ItemsPanel> 
     <ItemsPanelTemplate> 
      <WrapPanel Width="{Binding (FrameworkElement.ActualWidth), RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}" 
         ItemWidth="{Binding (ListBox.View).ItemWidth, RelativeSource={RelativeSource AncestorType=ListBox}}" 
         MinWidth="{Binding ItemWidth, RelativeSource={RelativeSource Self}}" 
         ItemHeight="{Binding (ListBox.View).ItemHeight, RelativeSource={RelativeSource AncestorType=ListBox}}" /> 
     </ItemsPanelTemplate> 
    </ListBox.ItemsPanel> 
    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <CheckBox Name="CheckBoxZone" Content="{Binding TheText}" Tag="{Binding TheValue}" Checked="CheckBoxZone_Checked" Margin="0,5,0,0"/> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 

该代码将包裹如果这不符合您的要求,那么我会建议你使用,而不是列表框格。

+0

谢谢队友.... –