我想将AnswerList
绑定到QuestionList
。当我运行代码时,屏幕上只有问题列表。
<ListBox x:Name="listques" ItemsSource="{Binding QuestionList }">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock x:Name="quesdetail" Text="{Binding QuestionContent.que_detail}" HorizontalAlignment="Left" Margin="27.669,34.338,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="252.564" Width="419.534" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" d:LayoutRounding="Auto">
</TextBlock>
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock x:Name="ansdetail" Foreground="Blue" Text="{Binding Answer.ans_detail}">
</TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
您在Question对象中应具有属性AnswerList
。将其分配为内部ListBox的itemsSource。因此,对于每个问题,您都会有一个答案列表。
@@贝尔斯是对的。要详细说明他的答案,让我通过一个外部示例进行解释。
A ListBoxItem将尝试在ItemSource中其当前项的属性内查找绑定。