C# 具有多列的列表框
我想在listbox中有多个列,其中包含我通过从数据库中获取值动态创建的复选框。代码如下:C# 具有多列的列表框,c#,wpf,xaml,listbox,C#,Wpf,Xaml,Listbox,我想在listbox中有多个列,其中包含我通过从数据库中获取值动态创建的复选框。代码如下: <StackPanel Width="250" Height="80"> <ListBox Name="listBoxZone" ItemsSource="{Binding TheList}" Height="115" Background="Azure"> <ListBox.ItemTemplate> <DataTemplate>
<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个复选框后更改列。。。我在这里使用了包裹面板,但它将所有复选框垂直对齐
那么现在该怎么办呢 您应该尝试以下方法:
<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>
当到达控件的宽度边界时,此代码将换行,而不是当项目计数达到5时。如果这不符合您的要求,那么我建议您使用网格而不是列表框。我不理解您的问题。你到底想要实现什么?“我想在5个复选框后更改列”是什么意思