我要绑定一个二维集合 - 收藏复杂数据类型的。因此,该控件的外观富文本框喜欢(n)的垂直列表(列)。
I want to bind a 2 dimensional collection - collection of collection of complex data type. So that the control looks likes (n) vertical lists(columns) of rich text boxes.
每个名单都会有记录数相同。
Each list will have same number of records.
一种方法是将数据传递到从视图模型视图,然后编程创建这些列表在XAML背后的code。但我并不想这样做,有没有更简单的东西?
One way is to pass the data to the view from viewmodel and then programmatically create these lists in the code behind of xaml. But I don't want to do that, is there something simpler?
只要使用数据绑定和模板:
Just use data binding and data templates:
<ItemsControl ItemsSource="{Binding MainCollection}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding .}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<RichTextBox Text="{Binding .}"/>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
所以外的ItemsControl
结合藏品的收集和呈现在垂直的StackPanel
。对于该集合中每个集合,有一个内在的的ItemsControl
。在其收藏为每个内部的ItemsControl
显示每一个项目一个的RichTextBox
在一个水平的StackPanel
。
So the outer ItemsControl
binds to the collection of collections and renders in a vertical StackPanel
. For each collection in that collection, there is an inner ItemsControl
. Each inner ItemsControl
displays every item in its collection as a RichTextBox
in a horizontal StackPanel
.
显然,你需要修复结合起来适当的路径和调整,根据需要为您的具体方案。
Obviously you will need to fix up binding paths as appropriate and tweak as necessary for your specific scenario.
上一篇:Android的,如何使用LoaderManager和放大器;装载机与sqldatabase结合放大器、如何使用、装载机、Android
下一篇:不能生成机器人工作室&QUOT签署APK,执行失败的任务“:packageRelease'&QUOT;机器人、任务、工作室、APK