File size: 1,039 Bytes
fab29d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using System.Windows;
using System.Windows.Controls;

namespace VersOne.Epub.WpfDemo.Controls
{
    /// <summary>
    /// A text block control that shows a tooltip with the content of its <see cref="TextBlock.Text" /> property if it is trimmed on the screen.
    /// </summary>
    public class TextBlockWithTooltip : TextBlock
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="TextBlockWithTooltip" /> class.
        /// </summary>
        public TextBlockWithTooltip()
        {
            SizeChanged += TextBlockWithTooltip_SizeChanged;
        }

        private void TextBlockWithTooltip_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
            if (ActualWidth < DesiredSize.Width)
            {
                ToolTipService.SetToolTip(this, Text);
            }
            else
            {
                ToolTipService.SetToolTip(this, null);
            }
        }
    }
}