2012-08-02 48 views
1

我想在WPF的RichTextBox創建簡單的「懶加載工具提示」爲超鏈接。如何衡量一個超鏈接元素的高度?

我此用彈出控制,如下所示:

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

您將要測量字體高度Font.Height然後使用此元素的基本位置來確定放置工具提示的高度

相關問題