Martin Bennedik

I would like to add a command to my application to add a row to a table in a RichTextBox.

Using reflector I can see that there is already code inside WPF to do this:

There is EditingCommands.InsertTable, EditingCommands.InsertRows etc., but they are all internal.

RichTextBox in its constructor even calls TextEditor.RegisterCommandHandlers, which registers command handlers for all these internal commands.

And these command handlers are even implemented in the TextRange.EditTables class.

Alas, all of this is only internal. I used the analyzer of reflector to see if there is any public way of accessing this functionality, but there doesn't seem to be.

Has anybody successfully implemented table commands in a WPF RichTextBox



Re: Windows Presentation Foundation (WPF) How to add a row to a table in a RichTextBox?

LesterLobo - MSFT

table editing currently supports the basic table operations. The operations are made internal so that the customers dont face problems in complex scenarios.

HTH





Re: Windows Presentation Foundation (WPF) How to add a row to a table in a RichTextBox?

Martin Bennedik

I assume with basic operations you mean inserting a table, a row, or a column, deleting a row or a column, and merging and splitting cells. These correspond to the EditingCommands.

But how can I access even those basic operations

I cannot even wire a menu or other UI element with those commands, because those commands are internal, too.





Re: Windows Presentation Foundation (WPF) How to add a row to a table in a RichTextBox?

LesterLobo - MSFT

when i mean basic operations... you can perform editing content on a table... The editing commands will likely become public in the future.





Re: Windows Presentation Foundation (WPF) How to add a row to a table in a RichTextBox?

Martin Bennedik

That doesn't answer the question how to add a row, though. I need to do this now, and cannot wait for an undisclosed future.

Are you saying the methods are internal because they are still buggy In that case, why were they not taken out completely Of course this is only academic interest, the real question is how to implement the table operations now.





Re: Windows Presentation Foundation (WPF) How to add a row to a table in a RichTextBox?

lee d

are you looking for something like this

RichTextBox doc = e.Source as RichTextBox;

if (doc != null)

{

Table t = new Table();

TableRowGroup trg = new TableRowGroup();

TableRow tr = new TableRow();

TableCell tcell = new TableCell();

tcell.Blocks.Add(new List(new ListItem(new Paragraph(new Run("this is some more text")))));

tr.Cells.Add(tcell);

trg.Rows.Add(tr);

t.RowGroups.Add(trg);

doc.Document.Blocks.Add(t);

}






Re: Windows Presentation Foundation (WPF) How to add a row to a table in a RichTextBox?

Martin Bennedik

No, I am looking for something different. Your method seems to add a table at the end of the RichTextBox. I would like to do the following:

-Cursor is inside a table in the RichTextBox

-User selects a command to add a row

-A row is added to the table, say below the row where the cursor is

There is already some complicated code in the WPF assemblies which does that, but it is unfortunately internal.





Re: Windows Presentation Foundation (WPF) How to add a row to a table in a RichTextBox?

lee d

you can do something like this, something similar could go in CanExecute handler for the command for inserting a row.

in the Executed handler of the command, you can do something similar to find the containing table and add row to that table

FrameworkContentElement fce = richTextBox1.CaretPosition.Paragraph as FrameworkContentElement;

while (fce != null)

{

if (fce is Table)

{

e.CanExecute = true;

return;

}

fce = fce.Parent as FrameworkContentElement;

}

e.CanExecute = false;