Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warn about CapsLock

I have a DataGridTemplateColumn with DataTemplate as a PasswordBox.

I want to warn user if CapsLock is toggled.

private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
    {
        if (Keyboard.GetKeyStates(Key.CapsLock) == KeyStates.Toggled)
        {  
         ...

Now, I need to raise some PopUp here. I don't know how to do this. Help me please.

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.

like image 959
iLemming Avatar asked Jul 07 '09 14:07

iLemming


People also ask

How do I turn off Caps Lock warning?

Hit the Windows key & type: Control Panel and then open it. Then steer to the Key Settings tab & double-click on Caps Lock. Now uncheck 'Displays Caps Lock Status on Screen' & reboot your PC.

Is Caps Lock rude?

While all caps can be used as an alternative to rich-text "bolding" for a single word or phrase, to express emphasis, repeated use of all caps can be considered "shouting" or irritating.

What is the meaning of Caps Lock?

a key on a computer keyboard that you press to make any letters you type appear as capital letters until you press it again.


1 Answers

You could show a ToolTip

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;
    }
}
like image 191
Patrick McDonald Avatar answered Sep 21 '22 04:09

Patrick McDonald