【问题标题】:Always show WPF TextBox Tooltip始终显示 WPF 文本框工具提示
【发布时间】:2011-07-20 10:32:52
【问题描述】:

是否可以一直显示tooltip,不取决于控件是否被聚焦,而只取决于绑定属性的值。

<TextBox Name="projectTextBox" 
         ToolTipService.Placement="Bottom" ToolTipService.ShowDuration="12000" 
         MinWidth="150" Text="{Binding ProjectName}" IsEnabled="{Binding IsEnabled}">
    <TextBox.ToolTip>
        <ToolTip Placement="Bottom" 
                 StaysOpen="True" Content="TEXT" 
                 Visibility="{Binding IsNotFound, Converter={StaticResource booleanToVisibilityCollapsedConverter}}" 
                 IsOpen="True">
        </ToolTip>
    </TextBox.ToolTip>
</TextBox>

【问题讨论】:

  • 你试过用 Popup 代替 Tooltip 吗?

标签: wpf tooltip visibility


【解决方案1】:

为什么不根据触发器设置工具提示?

<TextBox Name="projectTextBox" ToolTipService.Placement="Bottom" ToolTipService.ShowDuration="12000" MinWidth="150" Text="{Binding ProjectName}" IsEnabled="{Binding IsEnabled}">
    <TextBox.Style>
        <Style TargetType="{x:Type TextBox}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsNotFound}" Value="False">
                    <Setter Property="ToolTip">
                        <Setter.Value>
                            <ToolTip Placement="Bottom" StaysOpen="True" Content="TEXT"  IsOpen="True" />
                        </Setter.Value>
                    </Setter>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </TextBox.Style>
</TextBox>

【讨论】:

    【解决方案2】:

    基本上,您不能强制工具提示不断显示,因为 Windows 决定何时隐藏工具提示(通常在 MouseLeave 或一段时间后)以保持应用程序的外观和感觉一致(工具提示控件是按这种方式操作的)。

    如果您想以不同于标准 Windows 工具提示方式的方式向用户显示一些有用的信息,您应该考虑使用工具提示以外的其他方式,可能是弹出窗口或类似于来自 this article 的 FormNotification 控件的方式.

    【讨论】:

      【解决方案3】:

      您应该为您正在寻找的行为使用装饰器。您可以根据需要使用数据触发器或想要向装饰者展示的内容。顺便说一句,您在移动主窗口时没有遇到弹出窗口的问题。

      【讨论】:

      • 我在网上查过了,我认为这正是我所需要的。我缺乏WPF的经验,所以不知道。感谢您的回答!
      【解决方案4】:

      您可以考虑改用 Popup。或者,如果您正在为 WPF 使用材料设计,则可以考虑使用 PopupBox。 我知道我这次聚会迟到了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-07-17
        • 1970-01-01
        • 1970-01-01
        • 2011-01-08
        • 1970-01-01
        • 1970-01-01
        • 2015-09-23
        • 1970-01-01
        相关资源
        最近更新 更多