开发者

Show some formatted text in WPF which the user can copy to word

I want to show some formatted text in a client WPF application which the user can select 开发者_运维知识库and copy to word.

It needs to be easily created by the app, and the biggest formatting thing inside is a table where some cells are right-aligned.

What is best to use here? A richtext control is hard to fill (I think) and html is not easy to show, isn't it?


Pretty sure RichTextBox should be your answer.

You would have a RichTextBox containing a FlowDocument containing your Tables.

From that first article:

The RichTextBox control enables you to display or edit flow content including paragraphs, images, tables, and more. This topic introduces the TextBox class and provides examples of how to use it in both Extensible Application Markup Language (XAML) and C#.

<RichTextBox>
  <FlowDocument>
    <Table>
      <TableRowGroup>
        <TableRow>
          <TableCell>
            <!-- One or more Block-derived object… -->
          </TableCell>
        </TableRow>
      </TableRowGroup>
    </Table>
  </FlowDocument>
</RichTextBox>

When content is copied from a RichTextBox, it's treated as standard RTF, so Word will recognize most (if not all) of the formatting.

Interesting thought: FlowDocuments are closely related to the XPS file format, which Windows 7/Vista can print natively to. There's a huge amount of interoperability between Silverlight/WPF/XPS and to some extent even Word 2007 docx files.

I even faintly remember editing an XPS file in Visual Studio's WPF designer -- though don't quote me on that, since it was quite a few years ago and I don't remember what exactly I did.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜