我想知道是否有一种方法(任何组件/控件)可以让我在应用程序窗口中绘制一个类似于Microsoft Word简单表格的样式。就像这样:
有什么想法吗?
我想知道是否有一种方法(任何组件/控件)可以让我在应用程序窗口中绘制一个类似于Microsoft Word简单表格的样式。就像这样:
有什么想法吗?
这取决于您想如何使用它。您可以使用其中一个ItemsControl
(如DataGrid
、ListView
等),直接使用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
我建议从WPF Toolkit DataGrid控件开始。
这里有一个关于如何使用它的不错教程: http://www.switchonthecode.com/tutorials/using-the-wpf-toolkit-datagrid
FlowDocument
。大约18个月前,我完成了一个中等规模的WPF应用程序,自那以后就没有再做过任何事情。我的Xaml技能已经生疏了 :( - Binary Worrier