TOC

This article is currently in the process of being translated into French (~31% done).

Contrôles RichText:

Introduction to WPF Rich Text controls

Dans d'autres frameworks d'interface utilisateur, tels que WinForm, afficher de larges quantités de texte richement formaté a pu être un problème. Bien sûr, vous pourriez charger un fichier dans un RichTextBox ou vous pourriez créer un objet WebBrowser et charger une page web locale ou en réseau. Cependant, déclarer de large quantité de texte richement formaté en temps réel n'était pas vraiment possible. Il semble que Microsoft ait décidé de remédier à cela dans WPF et d'aller encore plus loin que l'affichage simple de texte.

The FlowDocument does indeed render rich text, and that even includes images, lists and tables, and elements can be floated, adjusted and so on, and using a FlowDocument, you can specify rich text in design-time as if it were HTML (thanks to XAML) and have it rendered directly in your WPF application.

The FlowDocument doesn't stand alone. Instead, it uses one of several built-in wrappers, which controls how the FlowDocument is laid out and whether the content can be edited by the user or not. WPF includes three controls for rendering a FlowDocument in read-only mode, which all has easy support for zooming and printing:

FlowDocumentScrollViewer - le plus simple encadreur atour d'un FlowDocument, qui affiche simplement le document comme un long document de texte dans le lequel vous pouvez scroller.

FlowDocumentPageViewer - this wrapper will automatically split your document into pages, which the user can navigate back and forth between.

FlowDocumentReader - a combination of the FlowDocumentScrollViewer and the FlowDocumentPageViewer, which will let the user decide between the two rendering modes. It also offers the ability AND the interface to search in the document.

The FlowDocument is normally read-only, but put it inside of a RichTextBox control (described later in this tutorial) and you can now edit the text, much like in real word processors like Microsoft Word.

Read on through the next chapters, where we'll discuss all the wrappers that you can use with a FlowDocument, both read-only and editable. After that, we'll look into all of the possibilities you have when creating rich documents using the FlowDocument, including tables, lists, images and much more.

This article has been fully translated into the following languages: Is your preferred language not on the list? Click here to help us translate this article into your language!