0

This one is tricky, I have a number of table cells in a flowdocument, I need to be able to indicate different items by a colored left border.

I've solved this currently by putting a 4 pixel transparent border on a tablecell with a name, and then using FindName to find that element and switching the borderbrush to a colored border.

  <TableCell BorderBrush="Transparent" BorderThickness="4 0 0 0" Padding="0 0 4 0" Name="cell_1"/>

The only problem is that is slow for large documents, I think changing the borderbrush on the TableCell is causing the whole layout to recalculate itself

Anyone have any ideas around this, I guess I either have to prevent the layout from recalculating, another option would be to try to find the rectangle/coordinates of the cell and overlay a marker but I have been able to find a way to do that.

I know flowdocument is not the most suited control for this kind of stuff but for layout reasons it's the one I have to use. Any help/ideas appreciated

Homde
  • 4,246
  • 4
  • 34
  • 50

1 Answers1

0

I would recommend using adorners. However, since TableCell doesn't inherit from UIContainer, you can't adorn it. Instead, you can set the content of each of the TableCell's BlockCollection to be a RichTextBox (use TextBox for better performance). Name the RichTextBox control and use FindName on this instead. Then create and add an Adorner for each of the cell's RichTextBox's you want to create a selection for.

If you can't use the nested RichTextBox, you can adorn the RichTextBox that owns the main FlowDocument. But this adds to the complexity because you now have to get the coordinates of your TableCell and do a transform relative to the RichTextBox.

Alex B
  • 2,766
  • 1
  • 17
  • 8
  • Wrapping the entire contents of the Cell sounds like it might interfere with the layout (since it wraps in columns), also having a richtextbox (which is needed for the content) is quite the overhead in itself – Homde Nov 16 '10 at 09:15