密码框工具提示没有出现

时间:2016-01-25 21:01:12

标签: c# wpf

我正在使用System.Windows.Controls.PasswordBox并想知道如何正确实现工具提示?

<PasswordBox    
    ToolTip="To Enable, please enter SMTP server and port"
    x:Name="Password" 
    Framework:PasswordBoxAssistant.BindPassword="true"
    Framework:PasswordBoxAssistant.BoundPassword="{Binding Path=Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
    VerticalContentAlignment="Center"
    IsEnabled="False" />

我在ToolTip Text中添加了但工具提示不会出现。

1 个答案:

答案 0 :(得分:3)

默认情况下,必须启用Control才能显示ToolTip。尝试将PasswordBox包装在没有可视化的元素内,并将ToolTip放在其上:

<Border ToolTip="To Enable, please enter SMTP server and port">
    <PasswordBox x:Name="Password" 
                 Framework:PasswordBoxAssistant.BindPassword="true"
                 Framework:PasswordBoxAssistant.BoundPassword="{Binding Path=Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                 VerticalContentAlignment="Center"
                 IsEnabled="False" />                
</Border>

使其工作的另一种方法是使用ToolTipService.ShowOnDisabled附加属性。这是更好的解决方案:

<PasswordBox ToolTip="To Enable, please enter SMTP server and port"
             x:Name="Password" 
             Framework:PasswordBoxAssistant.BindPassword="true"
             Framework:PasswordBoxAssistant.BoundPassword="{Binding Path=Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
             VerticalContentAlignment="Center"
             IsEnabled="False"
             ToolTipService.ShowOnDisabled="True" />