我正在使用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中添加了但工具提示不会出现。
答案 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" />