在WPF中创建一个简单的表? [英] Creating a simple Table in WPF?

查看:135
本文介绍了在WPF中创建一个简单的表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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





任何想法?

解决方案

这取决于你的使用方式。使用 ItemsControl 之一(如 DataGrid ListView 等等),直接使用 Grid 面板(如其他答案所建议的)或使用 FlowDocument p>

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



 < FlowDocumentReader UseLayoutRounding =TrueSnapsToDevicePixels =True> 
< FlowDocumentReader.Resources>
< Style TargetType =TableCell>
< Setter Property =TextAlignmentValue =Center/>
< / Style>
< /FlowDocumentReader.Resources>
< FlowDocument>
< Table CellSpacing =0>
< Table.Columns>
< TableColumn />
< TableColumn />
< TableColumn />
< TableColumn />
< /Table.Columns>
< TableRowGroup>
< TableRow>
< TableCell BorderBrush =BlackBorderThickness =1>
< Paragraph FontWeight =Bold>类别< / Paragraph>
< / TableCell>
< TableCell BorderBrush =BlackBorderThickness =0,1,1,1>
< Paragraph FontWeight =Bold> A< / Paragraph>
< / TableCell>
< TableCell BorderBrush =BlackBorderThickness =0,1,1,1>
< Paragraph FontWeight =Bold> B< / Paragraph>
< / TableCell>
< TableCell BorderBrush =BlackBorderThickness =0,1,1,1>
< Paragraph FontWeight =Bold> C< / Paragraph>
< / TableCell>
< / TableRow>
< TableRow>
< TableCell BorderBrush =BlackBorderThickness =1,0,1,1>
< Paragraph FontWeight =Bold> Subscription< / Paragraph>
< / TableCell>
< TableCell BorderBrush =BlackBorderThickness =0,0,1,1>
< Paragraph> Monthly< / Paragraph>
< / TableCell>
< TableCell BorderBrush =BlackBorderThickness =0,0,1,1>
< Paragraph> Yearly< / Paragraph>
< / TableCell>
< TableCell BorderBrush =BlackBorderThickness =0,0,1,1>
< Paragraph> Monthly< / Paragraph>
< / TableCell>
< / TableRow>
< TableRow>
< TableCell BorderBrush =BlackBorderThickness =1,0,1,1TextAlignment =Center>
< Paragraph FontWeight =Bold>价格< / Paragraph>
< / TableCell>
< TableCell BorderBrush =BlackBorderThickness =0,0,1,1>
<段落> $ 120.00< /段落>
< / TableCell>
< TableCell BorderBrush =BlackBorderThickness =0,0,1,1>
<段落> $ 1000.00< /段落>
< / TableCell>
< TableCell BorderBrush =BlackBorderThickness =0,0,1,1>
< Paragraph> $ 130.00< / Paragraph>
< / TableCell>
< / TableRow>
< / TableRowGroup>
< / Table>
< / FlowDocument>
< / FlowDocumentReader>

这个页面充满了有用的例子: FlowDocument with Table


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:

Any ideas?

解决方案

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 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>

This page is full of usefull examples about this: FlowDocument with Table

这篇关于在WPF中创建一个简单的表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆