Search code examples
c#wpfflowdocument

WPF Documents: How to create paragraphs of "underlines" on which you can write answers to questionnaires


I am creating an application that is meant to print out forms meant to be filled in by humans writing on paper. These documents follow a question and answer style. Typically you have paragraphs with an "underline" style onto which a free-form answer of paragraph length can be written.

How would you create this using WPF Documents?

Here is a mockup of what I mean, done using Word with tables and tabstops:

mock up http://img147.imageshack.us/img147/9350/questionnaire.png


Solution

  • I finally found a way to achieve this, thought I would share.

    Create the outside table with two rows and two columns like you would expect.

    For the underlines, create three different tables, each with only one row and column, with a border applied only to the bottom.

    This is how it looks in code:

            for (int i = 1; i < pQuestionSpec.NumberOfLines; i++)
            {
                Table innerT = new Table();
                var col1 = new TableColumn();
    
                col1.Width = new GridLength(1, GridUnitType.Star);
                innerT.Columns.Add(col1);
    
                var innerRowGroup = new TableRowGroup();
                var innerRow = new TableRow();
    
                var cell2 = new TableCell();
                cell2.BorderThickness = new Thickness(0, 0, 0, 1);
                cell2.BorderBrush = Brushes.Black;
                cell2.Blocks.Add(new Paragraph());
    
                innerRow.Cells.Add(cell2);
                innerRowGroup.Rows.Add(innerRow);
    
                innerT.RowGroups.Add(innerRowGroup);
    
                cell.Blocks.Add(innerT);
            }