如何在RichTextBox中显示TableCell的工具提示

时间:2015-11-28 19:17:46

标签: c# wpf richtextbox

我在 RichTextBox 中插入,使用给定的工具提示添加 TableCell 。像这样:

Table table = new Table();
table.Columns.Add(new TableColumn());
table.RowGroups.Add(new TableRowGroup());
TableRow r = new TableRow();
table.RowGroups[0].Rows.Add(r);
var ci = new TableCell(new Paragraph(new Run("Text here")));
ci.ToolTip = "tooltip to be displayed";
r.Cells.Add(ci);

或者这个:

<RichTextBox  IsReadOnly="True">
     <FlowDocument >
         <Table>
             <TableRowGroup>
                 <TableRow>
                      <TableCell ToolTip="This is a tooltip">
                            <Paragraph>
                                 <Run>......somthing......</Run>
                            </Paragraph>
                      </TableCell>
                 </TableRow>
              </TableRowGroup>
          </Table>
      </FlowDocument>
</RichTextBox>

但这不起作用。我检查了 TableCell PreviewMouseMove 事件。

感谢任何帮助。

2 个答案:

答案 0 :(得分:2)

您需要允许在禁用控件上显示工具提示:

<RichTextBox  IsReadOnly="True">
    <FlowDocument >
        <Table>
            <TableRowGroup>
                <TableRow>
                    <TableCell BorderThickness="2" BorderBrush="Black" ToolTip="This is a tooltip" ToolTipService.ShowOnDisabled="True">
                        <Paragraph>
                            <Run>......something......</Run>
                        </Paragraph>
                    </TableCell>
                </TableRow>
            </TableRowGroup>
        </Table>
    </FlowDocument>
</RichTextBox>

答案 1 :(得分:0)

设置ToolTipServices.ShowOnDisabled =“True”,如下所示:

 <RichTextBox  IsReadOnly="True">
            <FlowDocument >
                <Table>
                    <TableRowGroup>
                        <TableRow>
                            <TableCell 
                                ToolTip="This is a tooltip" 
                                ToolTipService.ShowOnDisabled="True">
                                <Paragraph>
                                    <Run>......somthing......</Run>
                                </Paragraph>
                            </TableCell>
                        </TableRow>
                    </TableRowGroup>
                </Table>
            </FlowDocument>
        </RichTextBox>