如何衡量超链接元素的高度?

时间:2012-08-02 11:55:55

标签: c# .net wpf hyperlink flowdocument

我想为WPF RichTextBox中的超链接创建简单的“延迟加载工具提示”。

我使用Popup控件执行此操作,如下所示:

    private Popup popup;
    private void Hyperlink_MouseEnter(object sender, MouseEventArgs e)
    {
        Hyperlink hyper = sender as Hyperlink;
        popup = new Popup();
        popup.Child = new Label() { Content = "content of the popup" };
        popup.IsOpen = true;
        var pos = e.GetPosition(richTextBox);
        popup.Placement = PlacementMode.RelativePoint;
        popup.PlacementTarget = richTextBox;
        popup.HorizontalOffset = pos.X;
        popup.VerticalOffset = pos.Y + 30;
    }

要实现这一点,我必须测量给定超链接元素的高度(以像素为单位),这样我就可以用正确的值替换这个“30”常量。

有没有办法在WPF中测量超链接的高度?

1 个答案:

答案 0 :(得分:1)

您将要测量字体高度Font.Height,然后将其与元素的基本位置一起使用,以确定放置工具提示的高度