Always show WPF TextBox Tooltip

牧云@^-^@ 提交于 2020-04-11 12:04:26

问题


Is it possible to display tooltip constantly, not depending on whether the control is focused ot not, but depending only on the value of the bind property.

<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>

回答1:


you should use an adorner for the behavior you are looking for. you can use a datatrigger or what you want to show the adorner as long as you want. btw with an adorner you did not have the problems popups have, while moving the mainwindow.




回答2:


Why not set the tooltip based on a trigger?

<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>



回答3:


Basically, you cannot force the tooltip to be shown constantly, because Windows is the one who decides when the tooltip hides (usually on MouseLeave or after some amount of time) to keep the look and feel of the applications consistent (The tooltip control is made to act this way).

If you want to display some helpful information to the user in a way that differs from the standard Windows tooltip way, you should consider using something else than a ToolTip, maybe a Popup or something similar with the FormNotification control from this article.



来源:https://stackoverflow.com/questions/5390895/always-show-wpf-textbox-tooltip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!