【问题标题】:Creating a simple Table in WPF?在 WPF 中创建一个简单的表?
【发布时间】:2011-11-15 03:45:39
【问题描述】:

我想知道是否有一种方法(任何组件/控件)可以让我在我的应用程序窗口中绘制一个简单的 Microsoft Word 样式表。像这样的:

有什么想法吗?

【问题讨论】:

    标签: wpf charts components


    【解决方案1】:

    我建议从WPF Toolkit DataGrid 控件开始。

    这是一个关于如何使用它的好教程: http://www.switchonthecode.com/tutorials/using-the-wpf-toolkit-datagrid

    【讨论】:

      【解决方案2】:

      这取决于你想如何使用它。使用ItemsControl 之一(如DataGridListView 等),直接使用Grid 面板(如其他答案所推荐)或使用FlowDocument

      FlowDocument 允许您指定表、行和列。您还可以一次选择多个单元格进行复制/粘贴等。

      <FlowDocumentReader UseLayoutRounding="True" SnapsToDevicePixels="True">
          <FlowDocumentReader.Resources>
              <Style TargetType="TableCell">
                  <Setter Property="TextAlignment" Value="Center"/>
              </Style>
          </FlowDocumentReader.Resources>
          <FlowDocument>
              <Table CellSpacing="0">
                  <Table.Columns>
                      <TableColumn/>
                      <TableColumn/>
                      <TableColumn/>
                      <TableColumn/>
                  </Table.Columns>
                  <TableRowGroup>
                      <TableRow>
                          <TableCell BorderBrush="Black" BorderThickness="1">
                              <Paragraph FontWeight="Bold">Category</Paragraph>
                          </TableCell>
                          <TableCell BorderBrush="Black" BorderThickness="0,1,1,1">
                              <Paragraph FontWeight="Bold">A</Paragraph>
                          </TableCell>
                          <TableCell BorderBrush="Black" BorderThickness="0,1,1,1">
                              <Paragraph FontWeight="Bold">B</Paragraph>
                          </TableCell>
                          <TableCell BorderBrush="Black" BorderThickness="0,1,1,1">
                              <Paragraph FontWeight="Bold">C</Paragraph>
                          </TableCell>
                      </TableRow>
                      <TableRow>
                          <TableCell BorderBrush="Black" BorderThickness="1,0,1,1">
                              <Paragraph FontWeight="Bold">Subscription</Paragraph>
                          </TableCell>
                          <TableCell BorderBrush="Black" BorderThickness="0,0,1,1">
                              <Paragraph>Monthly</Paragraph>
                          </TableCell>
                          <TableCell BorderBrush="Black" BorderThickness="0,0,1,1">
                              <Paragraph>Yearly</Paragraph>
                          </TableCell>
                          <TableCell BorderBrush="Black" BorderThickness="0,0,1,1">
                              <Paragraph>Monthly</Paragraph>
                          </TableCell>
                      </TableRow>
                      <TableRow>
                          <TableCell BorderBrush="Black" BorderThickness="1,0,1,1" TextAlignment="Center">
                              <Paragraph FontWeight="Bold">Price</Paragraph>
                          </TableCell>
                          <TableCell BorderBrush="Black" BorderThickness="0,0,1,1">
                              <Paragraph>$120.00</Paragraph>
                          </TableCell>
                          <TableCell BorderBrush="Black" BorderThickness="0,0,1,1">
                              <Paragraph>$1000.00</Paragraph>
                          </TableCell>
                          <TableCell BorderBrush="Black" BorderThickness="0,0,1,1">
                              <Paragraph>$130.00</Paragraph>
                          </TableCell>
                      </TableRow>
                  </TableRowGroup>
              </Table>
          </FlowDocument>
      </FlowDocumentReader>
      

      这个页面有很多有用的例子:FlowDocument with Table

      【讨论】:

      • +1 我不知道 FlowDocument 大约 18 个月前我完成了一个中型 WPF 应用程序,从那以后就什么也没做。我的 Xaml-Fu 已经生锈了 :(
      • 出于某种奇怪的原因,当我创建一个表时,我得到一个搜索字段和我的表的不同视图。如何删除所有这些信息,只包含表格而不包含额外的花哨功能?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-21
      相关资源
      最近更新 更多