我正在使用 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" />
我添加了工具提示文本,但工具提示没有出现。
最佳答案
默认情况下,必须启用 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
附属属性(property)。这是更好的解决方案:
<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" />
关于c# - 密码框工具提示未出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35002288/