Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过单击事件将表添加到RichTextBox_C#_Wpf_Xaml - Fatal编程技术网

C# 通过单击事件将表添加到RichTextBox

C# 通过单击事件将表添加到RichTextBox,c#,wpf,xaml,C#,Wpf,Xaml,我想通过单击事件以编程方式添加表。 默认情况下,我尝试实现两列两行。具有在单元格上打开或聚焦的功能,可以将行/列附加到表中 我找到了桌子,也不允许在运行时调整宽度或高度 以下是我到目前为止的情况: XAML <Grid> <RichTextBox x:Name="contentRichTextBox" TextChanged="ContentRichTextBox_TextChanged"

我想通过单击事件以编程方式添加表。 默认情况下,我尝试实现两列两行。具有在单元格上打开或聚焦的功能,可以将行/列附加到表中

我找到了桌子,也不允许在运行时调整宽度或高度

以下是我到目前为止的情况:

XAML

<Grid>
    <RichTextBox x:Name="contentRichTextBox"
                 TextChanged="ContentRichTextBox_TextChanged"
                 SelectionChanged="ContentRichTextBox_SelectionChanged" Grid.ColumnSpan="3">
    </RichTextBox>
</Grid>

C#

private void Table\u单击(对象发送者,路由目标)
{
Table=new();
contentRichTextBox.Document.Blocks.Add(表);
Border=new();
border.BorderBrush=画笔.黑色;
border.BorderThickness=新厚度(1);
//创建列并将它们添加到表的columns集合中。
int numberOfColumns=2;
对于(int x=0;x
private void Table_Click(object sender, RoutedEventArgs e)
{
    Table table = new();
    contentRichTextBox.Document.Blocks.Add(table);

    Border border = new();
    border.BorderBrush = Brushes.Black;
    border.BorderThickness = new Thickness(1);

    // Create columns and add them to the table's Columns collection.
    int numberOfColumns = 2;

    for (int x = 0; x < numberOfColumns; x++)
    {
        table.Columns.Add(new TableColumn());
    }

    //Create and add empty TableRowGroup to hold the tables rows
    table.RowGroups.Add(new TableRowGroup());

    //add the first row
    table.RowGroups[0].Rows.Add(new TableRow());

    //alias the current working row for easy reference
    TableRow currentRow = table.RowGroups[0].Rows[0];

    //add the second header row
    table.RowGroups[0].Rows.Add(new TableRow());
    currentRow = table.RowGroups[0].Rows[1];

    //add cells with content to second row
    currentRow.Cells.Add(new TableCell(new Paragraph(new Run(" "))) { BorderBrush = Brushes.Black, BorderThickness = new Thickness(1) });
    currentRow.Cells.Add(new TableCell(new Paragraph(new Run(" "))) { BorderBrush = Brushes.Black, BorderThickness = new Thickness(1) });

    //add the third row
    table.RowGroups[0].Rows.Add(new TableRow());
    currentRow = table.RowGroups[0].Rows[2];

    //add cells with content to the third row
    currentRow.Cells.Add(new TableCell(new Paragraph(new Run(" "))) { BorderBrush = Brushes.Black, BorderThickness = new Thickness(1) });
    currentRow.Cells.Add(new TableCell(new Paragraph(new Run(" "))) { BorderBrush = Brushes.Black, BorderThickness = new Thickness(1) });

    //table styling
    table.CellSpacing = 0;
}