如何在控件聚焦时不断显示工具提示? [英] How can I display a tooltip constantly while a control is focused?

查看:19
本文介绍了如何在控件聚焦时不断显示工具提示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在控件获得焦点时不断显示工具提示?我已经尝试了很多东西,但似乎没有任何效果.现在我有类似以下内容:

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>

看起来它应该很简单地工作,但事实并非如此.为什么不?我将工具提示的 IsOpen 属性绑定到文本框的 IsKeyboardFocused 属性.因此,它应该在工具提示聚焦时显示.为什么不呢?

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?

推荐答案

您可以像这样使用 Popup 而不是 ToolTip:

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.

这篇关于如何在控件聚焦时不断显示工具提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆