简体   繁体   English

如何在控件聚焦时不断显示工具提示?

[英]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. 我将工具提示的IsOpen属性绑定到文本框的IsKeyboardFocused属性。 Therefore, it should display while the tooltip is focused. 因此,它应在工具提示聚焦时显示。 Why doesn't it? 为什么不呢?

You can use a Popup instead of a ToolTip like this: 您可以使用Popup而不是ToolTip如下所示:

<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. 然后将其设计为看起来像工具提示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM