Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I display a tooltip constantly while a control is focused?

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?

like image 606
Rich Avatar asked Jan 06 '11 21:01

Rich


1 Answers

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.

like image 76
Rick Sladkey Avatar answered Nov 09 '22 23:11

Rick Sladkey