8

How can I display a tooltip constantly while a control is focused? I've tried so many things and nothing seems to work. Right now I have something like the following:

    <TextBox x:Name="textBox" Width="200">
        <TextBox.ToolTip>
            <ToolTip StaysOpen="{Binding IsKeyboardFocused, ElementName=textBox}" IsOpen="{Binding IsKeyboardFocused, ElementName=textBox}">
                Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
            </ToolTip>
        </TextBox.ToolTip>
    </TextBox>

It seems like it should work very simply, but it doesn't. Why not? I'm binding the tooltip's IsOpen property to the textbox's IsKeyboardFocused property. Therefore, it should display while the tooltip is focused. Why doesn't it?

Rich
  • 3,081
  • 1
  • 22
  • 24
  • 1
    Have you seen this SO-Question: http://stackoverflow.com/questions/896574/forcing-a-wpf-tooltip-to-stay-on-the-screen ? – Tim Schmelter Jan 06 '11 at 21:33

1 Answers1

12

You can use a Popup instead of a ToolTip like this:

<Grid>
    <StackPanel>
        <TextBox x:Name="textBox1" Width="200" Height="20"/>
        <TextBox x:Name="textBox2" Width="200" Height="20"/>
    </StackPanel>
    <Popup PlacementTarget="{Binding ElementName=textBox1}" IsOpen="{Binding IsKeyboardFocused, ElementName=textBox1, Mode=OneWay}">
        <TextBlock Background="White">
            <TextBlock.Text>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</TextBlock.Text>
        </TextBlock>
    </Popup>
</Grid>

and then style it to look like a tool tip.

Rick Sladkey
  • 33,988
  • 6
  • 71
  • 95
  • How to style it to look like a tooltip? – marczellm Jul 31 '14 at 10:24
  • "*You can use a Popup instead of a ToolTip*", is there any reason to not use a ToolTip (unless you explain this, this is not an answer to the question "*How can I display a tooltip constantly*" which implicitly asked why `StaysOpen` doesn't work as expected -- it seems there is some interference between this property and `ToolTipService.ShowDuration`) – mins Nov 14 '19 at 12:08