关于 CapsLock 的警告 [英] Warn about CapsLock
本文介绍了关于 CapsLock 的警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 DataGridTemplateColumn,其中 DataTemplate 作为 PasswordBox.
I have a DataGridTemplateColumn with DataTemplate as a PasswordBox.
如果 CapsLock 被切换,我想警告用户.
I want to warn user if CapsLock is toggled.
private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
{
if (Keyboard.GetKeyStates(Key.CapsLock) == KeyStates.Toggled)
{
...
现在,我需要在这里提出一些 PopUp.我不知道该怎么做.请帮帮我.
Now, I need to raise some PopUp here. I don't know how to do this. Help me please.
我尝试像这样使用 ToolTip:
I tried to play around with ToolTip like this:
((PasswordBox)sender).SetValue(ToolTipService.InitialShowDelayProperty, 1);
((PasswordBox)sender).ToolTip = "CAPS LOCK";
但它只有在鼠标光标悬停在那里时才有效,我需要一个独立的弹出窗口.
But it works only when mouse cursor hovers there and I need an independent Popup.
推荐答案
您可以显示工具提示
private void PasswordBox_KeyDown(object sender, KeyEventArgs e)
{
if ((Keyboard.GetKeyStates(Key.CapsLock) & KeyStates.Toggled) == KeyStates.Toggled)
{
if (PasswordBox.ToolTip == null)
{
ToolTip tt = new ToolTip();
tt.Content = "Warning: CapsLock is on";
tt.PlacementTarget = sender as UIElement;
tt.Placement = PlacementMode.Bottom;
PasswordBox.ToolTip = tt;
tt.IsOpen = true;
}
}
else
{
var currentToolTip = PasswordBox.ToolTip as ToolTip;
if (currentToolTip != null)
{
currentToolTip.IsOpen = false;
}
PasswordBox.ToolTip = null;
}
}
这篇关于关于 CapsLock 的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文