我有以下结构
QPage
类对象包含一个List<List<QLine>>
QLine
对象包含List<Qword>
每个单词列表构成一个行,每个单词列表构成一个组(段落),每个段落列表构成一个页面。
我想将页面绑定到XAML中的结构
<ListView>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock>
</TextBlock>
</StackPanel>
</StackPanel>
</ListView>
其中ListView的每个项目都是一个段落(List<QLine>
),每个垂直堆栈面板都包含的项目,List<QLine>
而水平堆栈面板的每个项目都包含的项目,List<Qword>
并且texblock绑定到Qword.text
属性。我不知道如何从XAML代码进行这种绑定。
希望我不会错过一些清单,但是应该可以。基本上,它ListBox
是托管List<List<QLine>>
(称为QPageList
)的主机。然后,您在垂直面板ItemsControl
中托管了每个主机List<QLine>
,最后又有一个ItemsControl
主机(称为)托管List<Qword>
了,每个主机都显示为水平QLine
QwordList
QWord
TextBlock
StackPanel
<!-- ItemsSource: List<List<QLine>>, Item: List<QLine> -->
<ListBox ItemsSource="{Binding QPageList}">
<ListBox.ItemTemplate>
<DataTemplate>
<!-- ItemsSource: List<QLine>, Item: QLine -->
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<!-- ItemsSource: QLine.List<QWord>, Item: QWord -->
<ItemsControl ItemsSource="{Binding QwordList}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<!-- Item: QWord -->
<TextBlock Text="{Binding text}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句