是否有一个RichTextBox等效于ListBox.ItemTemplate?

时间:2015-03-02 19:26:32

标签: c# wpf

是否有一个RichTextBox等效于ListBox.ItemTemplate?

<ListBox.ItemTemplate>
  <DataTemplate>
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" SharedSizeGroup="Col0"/>
        <ColumnDefinition Width="Auto" SharedSizeGroup="Col1"/>
        <ColumnDefinition Width="Auto" SharedSizeGroup="Col2"/>
      </Grid.ColumnDefinitions>
      <TextBlock Grid.Column="0" Text="{Binding tabType}"/>
      <TextBlock Grid.Column="1" Text="{Binding tabPhone}"/>
      <TextBlock Grid.Column="2" Text="{Binding tabLast}"/>
    </Grid>
  </DataTemplate>

此ListBox.ItemTemplate与类(tabType {get; set;})相结合,将显示组织成列。


50分钟后编辑。

上面的ListBox代码产生三列。目标是让RichTextBox有三列。

1 个答案:

答案 0 :(得分:0)

您在RichTextBox中使用FlowDocument并使用Table控件来显示表格或网格之类的数据。请参阅以下代码。

 <RichTextBox Margin="10">
        <FlowDocument>
            <Table>                   
                <Table.Columns>
                    <TableColumn />
                    <TableColumn />
                    <TableColumn />
                </Table.Columns>                   
                <TableRowGroup>                      
                    <TableRow>
                        <TableCell>                                
                            <Paragraph>Cell at Row 1 Column 1</Paragraph>
                        </TableCell>
                        <TableCell>
                            <Paragraph>Cell at Row 1 Column 2</Paragraph>
                        </TableCell>
                        <TableCell>
                            <Paragraph>Cell at Row 1 Column 3</Paragraph>
                        </TableCell>
                    </TableRow>
                    <TableRow>
                        <TableCell>
                            <Paragraph>Cell at Row 2 Column 1</Paragraph>
                        </TableCell>
                        <TableCell>
                            <Paragraph>Cell at Row 2 Column 2</Paragraph>
                        </TableCell>
                        <TableCell>
                            <Paragraph>Cell at Row 2 Column 3</Paragraph>
                        </TableCell>
                    </TableRow>
                </TableRowGroup>
            </Table>
        </FlowDocument>
    </RichTextBox>

在LisBox中我们可以绑定到集合,但在这里我不知道如何在RichTextBox和表中实现相同的功能。

相关问题