Office-like WPF Tooltip for Hyperlinks

You can have Office-like tooltips for the hyperlinks displayed in RichTextBox control in WPF. First thing to note is enabling the hyperlinks in RichTextBox by setting IsDocumentEnabled property. Then, we will bind the ToolTip property of the hyperlink to its NavigateUri property to be able to use it in the new DataTemplate of the ToolTip. The DataTemplate is defined so that when RichTextBox is editable the tooltip will display “Ctrl + Click to follow link” along with the navigation address, but in read-only mode the helper text will be “Click to follow link”.







Code Snippet

<RichTextBox Grid.Column="1" IsDocumentEnabled="True" IsReadOnly="True">



            <Hyperlink NavigateUri="">

                Go to msdn





        <Style TargetType="{x:Type Hyperlink}">

            <Setter Property="ToolTip" Value="{Binding Path=NavigateUri, RelativeSource={RelativeSource Self}}"/>



        <Style TargetType="ToolTip">

            <Setter Property="ContentTemplate">




                            <TextBlock Text="{Binding}"/>

                            <TextBlock x:Name="MessageTextBlock" FontWeight="Bold" Text="Ctrl + Click to follow link"/>



                            <DataTrigger Binding="{Binding Path=IsReadOnly, RelativeSource={RelativeSource AncestorType={x:Type RichTextBox}}}" Value="True">

                                <Setter TargetName="MessageTextBlock" Property="Text"  Value="Click to follow link"/>









Skip to main content