Jeff Powell
Jeff Powell

Reputation: 11

Display Tooltip in Center of Screen

Using Grid to display pictures around edge of screen.

<Image Source="...." Grid.Row="0" Grid.Column="0">
    <Image.Tooltip>
        <TextBlock>Some narrative..</TextBlock>

<TextBox Name="ToolTipText" Grid.Row="1" Grid.Column="1" />

On MouseOver I want the tooltip to appear in TextBox, but it aways appears centered over the image.

<Style TargetType="ToolTip">
    <Setter Property="PlacementTarget" 
        Value="{Binding ElementName=ToolTipText, Path=Text} />
    <Setter Property="Placement" Value="Center" />

Upvotes: 1

Views: 1093

Answers (1)

Fredrik Hedblad
Fredrik Hedblad

Reputation: 84674

Try this

<Grid Name="mainGrid">
    <Image Source="...." Grid.Row="0" Grid.Column="0" ToolTipService.PlacementTarget="{Binding ElementName=mainGrid}">
        <Image.ToolTip>
            <ToolTip Placement="Center">
                <TextBlock>Some narrative..</TextBlock>
            </ToolTip>
        </Image.ToolTip>
    </Image>
</Grid>

This

ToolTipService.PlacementTarget="{Binding ElementName=mainGrid}"

Can be replaced by

ToolTipService.PlacementTarget="{Binding RelativeSource={RelativeSource AncestorType={x:Type Grid}}}"

Upvotes: 1

Related Questions