views:

38

answers:

4

i would like to make a textblock tooltip conditionally visible.

i have the tooltip defined as:

<TextBlock>
    <TextBlock.ToolTip>
        <Grid>...</Grid>
    </TextBlock.ToolTip>
</TextBlock>

where would visibility property go in that definition? it doesn't seem to like any of my guesses.

there are some suggestions of just working with grid visibility. the problem with that approach is making the grid invisible will still show empty tooltip box.. which is why i am trying to control tooltip visibility.

A: 

You should set the visibility on the grid :

<Window.Resources>
    <BooleanToVisibilityConverter x:Key="visibilityConverter" />
</Window.Resources>


...

<Grid Visibility="{Binding IsToolTipVisible, Converter={StaticResource visibilityConverter}}>
...
</Grid>
Thomas Levesque
+2  A: 

Here you go;

   <TextBlock Text="Dummy text">
        <TextBlock.ToolTip>
            <ToolTip Visibility="Collapsed">
                <TextBlock Text="Text tooltip"></TextBlock>
            </ToolTip>                
        </TextBlock.ToolTip>
    </TextBlock>
NetSide
i would like to control tooltip visibility. if i make grid invisible, it will still show empty tooltip frame.
Sonic Soul
Try it in TextBlock like "<TextBlock Visibility="Visible">"
NetSide
i don't want to make the textblock invisible. just the tooltip
Sonic Soul
I edit my answer try it.
NetSide
+2  A: 

Try this. It won't leave an empty frame.

<TextBlock Text="test">
        <TextBlock.ToolTip>
            <ToolTip Visibility="Visible">
                Hello
            </ToolTip>
        </TextBlock.ToolTip>
    </TextBlock>

<TextBlock Text="test">
        <TextBlock.ToolTip>
            <ToolTip Visibility="Hidden">
                Hello
            </ToolTip>
        </TextBlock.ToolTip>
    </TextBlock>
Chris Persichetti
A: 

Hi Sonic,

If you don'e want the tooltip to show empty frame. You should create a separate tooltip ControlTemplate with all your required grid and textblocks and assign it to the tooltip template. This could help you solve the empty frame problem.

Avatar