Search code examples
c#wpfxamlcanvastooltip

An user control as Tool tip for WPF TextBlock


I have a TextBlock having a canvas as its ToolTip. An user control is bounded to the canvas from the back-end in constructor. The TextBlock defined in xaml as follows:

<TextBlock Width="60" Height="40" Text="More info.">
        <TextBlock.ToolTip>
            <Canvas Name="canToolTip"></Canvas> 
        </TextBlock.ToolTip>
</TextBlock>

The constructor definition will be :

 public UC_PublicationAdd()
    {
        InitializeComponent();
        // assign datacontext
        canToolTip.Children.Add(new ToolTipControl());
    }

The whole scenario is fine Now let me come to the Problem. When i place the mouse over the TextBlock ToolTip is showing but its size is not controllable. What i mean is that, size of tooltip is too smaller(default size when tooltip text is not present). I want the tooltip equal to the size of the canvas


Solution

  • Sorry for Make you Confused, finally i solved the issue by assigning width and height to the canvas inside the tooltip. The xaml looks like the following:

    <TextBlock Width="60" Height="40" Text="More info.">
           <TextBlock.ToolTip>
              <Canvas Name="canToolTip" Height="80" Width="130"></Canvas> 
           </TextBlock.ToolTip> 
    </TextBlock>