Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Document: Getting the Table Cell borders right

I created this pic in MS Word and I am trying to replicate the style in my WPF app using the Documents. First the 'from':

alt text http://img337.imageshack.us/img337/1275/correntborder.png

Next my attempt to replicate:

alt text http://img156.imageshack.us/img156/1711/extrawhiteborder.png

My question is probably rather obvious. What am I doing wrong? I can't find a padding property on the rowgrouping or the row. Below is my code:

    public override FlowDocument CreateDocumentSection(IInteractivityElement pElement)
    {
        var result = new FlowDocument();

        // show the header
        result.Blocks.Add(CreateHeading(pElement.Header));

        // we don't show anything else if there aren't any columns
        var nrColumns = pElement.GetIntegralData("CurrentColumnCount") ?? 0;
        if (nrColumns == 0) return result;

        Table mainTable = new Table();
        result.Blocks.Add(mainTable);

        // columns
        for (long tableIdx = 0; tableIdx < nrColumns; tableIdx++)
        {
            var newColumn = new TableColumn();
            mainTable.Columns.Add(newColumn);
        }

        // row group for header
        TableRowGroup rowGroup = new TableRowGroup();
        mainTable.RowGroups.Add(rowGroup);

        // row for header
        TableRow headerRow = new TableRow();
        headerRow.Background = new SolidColorBrush(Color.FromRgb(79, 129, 189));
        headerRow.Foreground = new SolidColorBrush(Colors.White);
        rowGroup.Rows.Add(headerRow);

        // add columns for each header cell
        for (long tableIdx = 0; tableIdx < nrColumns; tableIdx++)
        {
            var headerNameKey = CreateColumnNameKey(tableIdx);
            TableCell headerCell = new TableCell(new Paragraph(new Run(pElement.GetStringData(headerNameKey))));
            headerRow.Cells.Add(headerCell);
        }

        TableRow emptyRow = new TableRow();
        emptyRow.Foreground = new SolidColorBrush(Colors.Gray);
        rowGroup.Rows.Add(emptyRow);

        TableCell emptyInstructionCell = new TableCell();
        emptyInstructionCell.BorderBrush = new SolidColorBrush(Color.FromRgb(79, 129, 189));
        emptyInstructionCell.BorderThickness = new Thickness(1.0);
        emptyInstructionCell.ColumnSpan = Convert.ToInt32(nrColumns);
        emptyInstructionCell.Blocks.Add(new Paragraph(new Run(pElement.Instruction)));
        emptyRow.Cells.Add(emptyInstructionCell);

        return result;
    }
like image 726
Pieter Breed Avatar asked Nov 04 '09 19:11

Pieter Breed


1 Answers

Unfortunately you cannot set the border for a TableRow in a FlowDocument. It is only available for the Table or the TableCell. Even I wonder why this was not provided.

Although one way to achieve a row border effect is to use border of all cells in conjunction with BorderThickness, and setting CellSpacing of the container Table to 0. For eg:

table.CellSpacing = 0;
...
cellLeft.BorderThickness= new Thickness(1, 1, 0, 1);
...
cellCenter.BorderThickness= new Thickness(0, 1);
...
cellRight.BorderThickness= new Thickness(0, 1, 1, 1);
like image 145
Yogesh Avatar answered Sep 28 '22 04:09

Yogesh