c# - 密码框工具提示未出现

标签 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" />

我添加了工具提示文本,但工具提示没有出现。

最佳答案

默认情况下,必须启用 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/

相关文章:

c# - 不能使用 ZipArchive 类

c# - 方法 'CommonCreateArrayTypeSymbol'没有实现

WPF MVVM : Notifying the View of a change to an element within an ObservableCollection?

WPF - 普通的最佳实践 [标签 :Input] Control

c# - WPF:数据绑定(bind)对于模态对话框是否重要?

c# - 框架 4 和框架 4 客户端配置文件 : What is the difference?

c# - 哪里有一个很好的 SQL CE 复制演示?

c# - 无法确定用户的配置路径(尝试获取修订号时)

c# - 带有图像的 XamlReader

c# - AvalonDock:多工具窗口布局