在 WPF 中创建一个简单的表? [英] Creating a simple Table in WPF?
问题描述
我想知道是否有一种方法(任何组件/控件)可以让我在我的应用程序窗口中绘制一个简单的 Microsoft Word 样式表.像这样的:
I was wondering if there is a way (any components/controls) that allow me to draw a simple Microsoft Word style table in my application window. Something like this:
有什么想法吗?
推荐答案
这取决于你想如何使用它.要么使用 ItemsControl
之一(如 DataGrid
、ListView
等),直接使用 Grid
面板(按照其他答案的建议)或使用 FlowDocument
It depends on how you want to use it. Either use one of the ItemsControl
(like DataGrid
, ListView
etc), do it directly with a Grid
panel (as recommended by the other answers) or use a FlowDocument
FlowDocument
允许您指定表、行和列.您还可以一次选择多个单元格进行复制/粘贴等.
FlowDocument
allows you to specify Tables, Rows and Columns. You can also select several cells at once for Copy/Paste etc.
<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表格
This page is full of usefull examples about this: FlowDocument with Table
这篇关于在 WPF 中创建一个简单的表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!