Try it: Create a FlowDocumentReader control

Cette page s’applique uniquement aux projets WPF

In the Properties panel, some properties are more complex than a single value. For example, some properties represent a collection of values, or represent an object with properties of its own. You can use the collection editor and the subproperty editor to modify these values.

The following procedure uses the subproperty and collection editors to show you how to add content to a FlowDocumentReader control.

[!REMARQUE]

You do not have to use this procedure to modify text in a FlowDocumentScrollViewer control. Instead, you can use the procedures in Edit text in Blend, Format text, and the other topics that are listed in the "How to" section in Drawing text.

To add content to a FlowDocumentReader control

  1. The FlowDocumentReader control is available from the Assets panel. In the Tools panel, click Assets JJ170170.0d8b8d29-1af9-418f-8741-be3097d76eab(fr-fr,VS.110).png.

  2. In the Controls category, click All to see all the available controls.

  3. Select the FlowDocumentReader control from the list of controls. A generic icon appears underneath the Assets button in the Tools panel, selected and ready to be added to the artboard.

  4. Draw a FlowDocumentReader on the artboard.

    A FlowDocumentReader control drawn on the artboard

    JJ170170.B4_controls_flowdocumentreader(fr-fr,VS.110).png

  5. With the FlowDocumentReader object selected in the Objects and Timeline panel, expand the Miscellaneous category in the Properties panel.

  6. Click the New button next to the Document property. The Document property is populated with a FlowDocument object, and the subproperty editor for the FlowDocument opens. You can expand and collapse the subproperty editor. The Document property can contain only one FlowDocument.

    [!REMARQUE]

    Properties that will display a subproperty editor are typically identified by a New button next to them, and an expander arrow JJ170170.6375953d-074c-421a-bbb3-6f5055b67b64(fr-fr,VS.110).png (if the property has content). If the property has default subproperties associated with them, a drop-down arrow will also appear next to the property. For example, the BitmapEffect property provides a drop-down list that includes the BevelBitmapEffect, BlurBitmapEffect, and other subproperties that you can select from.

  7. In the subproperty editor for the Document property, click the Edit items in this collection button next to the Blocks (Collection) property. The collection editor opens for the Blocks property.

    [!REMARQUE]

    Properties that will display a collection editor are typically identified by the word (Collection) next to the property name, and by an Edit items in this collection button.

    The collection editor of the Blocks subproperty

    JJ170170.7becf751-36c9-49f0-a8bd-6308397e82ea(fr-fr,VS.110).png

  8. In the collection editor for the Blocks subproperty, click the drop-down arrow next to the Add button, select <other type…>, and then click the Add button. The Select Object window appears, from which you can select any Windows Presentation Foundation (WPF) object.

  9. In the Search text box, type Paragraph to quickly locate the Paragraph class. Select Paragraph from the list under System.Windows.Documents, and then click OK. The Select Object window closes, and a Paragraph item is added to the collection editor at index 0. The properties of the Paragraph object are displayed on the right side.

    [!REMARQUE]

    It can be difficult to understand which objects are valid for a given collection. For collection properties of common controls (such as the Items collection property of the ListBox control), the collection editor provides a drop-down list of suggested items in addition to the Add button. However, for less common controls (such as the FlowDocumentReader control), if might help you understand which objects are valid for the collection to view the MSDN documentation for the control type. For example, in the Flow Related Classes section of the Flow Document Overview on MSDN, a diagram shows the structure of flow document controls. From that diagram, you can see that the Blocks property can contain a Paragraph, Section, List, Table, and/or a BlockUIContainer object. In the following steps, you will add a Run element to the Inlines collection property of the Paragraph object.

  10. In the Properties window of the Paragraph object, click the Edit items in this collection button next to the Inlines property. The collection editor switches to the scope of the Inlines property.

  11. Click the drop-down arrow next to the Add button, select <other type…>, and then, click the Add button, expand PresentationFramework and System.Windows.Documents objects, and then select the Run class from the Select Object window. Click the Add button again and the Run object will be added to the collection editor at index 0.

  12. In the Properties window of the Run object, add content by typing in the Text property. You can also use some of the properties of the Brushes and Text categories to style the text. Other properties are disabled because they have to be set at the level of the FlowDocumentViewer control.

    The collection editor of the Inlines property after adding a Run object and editing the Text

    JJ170170.36430950-044e-44e8-a70f-c5fa9fc7ddde(fr-fr,VS.110).png

  13. Click OK to exit the collection editor for the Inlines property, and then click OK to exit the collection editor of the Blocks property. The text that you entered in the previous step is displayed in the FlowDocumentViewer control.

    Important

    Do not click the New button next to the Document property of the FlowDocumentViewer object unless you want to delete the content that you just created, because the Document property can contain only one FlowDocument object. Unless a property name includes the word (Collection), the property can contain only a single object.

    [!REMARQUE]

    If you are editing a FlowDocumentScrollViewer or a RichTextBox object, you can use the Blend for Visual Studio 2012 text editor, which can be accessed by selecting the object and then pressing F2. For more information, see Edit text in Blend. If you are editing a DocumentViewer or a FlowDocumentPageViewer object, content is added programmatically.