我试图在列表视图中显示这个嵌套列表。
例如,如果EventItem有响应,我需要在每个响应中重复事件名称x次。每个响应都有3个复选框。
我要做的是在一个列表中显示:
EventName -> Response Option -> Check Boxes of Effort.
我不想使用树,因此列表是单行的。什么好主意吗?
更新:假设有2个事件,事件1有2个选项,事件2有3个选项。每个选项将有3个复选框。
我如何尝试显示数据是这样的:
Event 1 Response A [X] [ ] [ ]
Event 1 Response B [ ] [X] [X]
Event 2 Response A [X] [X] [X]
Event 2 Response D [ ] [ ] [X]
Event 2 Response E [X] [X] [X]
对于Response,我需要重复事件名称。
public class EventItem: DataAttributeChecked
{
public EventItem(int primaryKey, string value) : base(primaryKey, value)
{
ResponseOptions = new List<ResponseOption>();
}
public List<ResponseOption> ResponseOptions { get; set; }
}
public class ResponseOption: DataAttribute
{
public ResponseOption(int primaryKey, string value, int eventId) : base(primaryKey, value)
{
_eventId = eventId;
LevelOfEfforts = new List<DataAttributeChecked>();
}
public List<DataAttributeChecked> LevelOfEfforts { get; set; }
private readonly int _eventId;
public int EventId
{
get { return _eventId; }
}
}
<ListBox.ItemTemplate>
<DataTemplate>
<Border Margin="3" CornerRadius="2" BorderBrush="CadetBlue" BorderThickness="1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Horizontal">
<CheckBox IsChecked="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}, Path=IsSelected}" />
<TextBlock Text="{Binding Value}" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<TextBlock Text="{Binding ResponseOption.Value}" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Grid.Column="2" Orientation="Horizontal">
<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ItemsSource="{Binding ResponseOptions.LevelOfEffort}"
Name="lstOption"
SelectionMode="Multiple" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="IsSelected" Value="{Binding Path=IsChecked, Mode=TwoWay}"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="3,3,3,3">
<CheckBox IsChecked="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}, Path=IsSelected}" />
<TextBlock Text="{Binding Value}" VerticalAlignment="Center"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</Grid>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
如果列表是嵌套的,你就有一个树,你可以使用HierarchicalDataTemplate并在TreeView或嵌套listview中显示。
如果您想在平面列表中查看,让你的ViewModel把树弄平,