#647 – You Can Treat Any Key As A Toggle Key

You typically use the IsToggled property in a keypress handler to check the state of a toggle key like Caps Lock.  But WPF actually keeps track of a “toggled” state for every key that you press.

For example, if you press the letter ‘a’ a number of times in a TextBox and look at the value of the IsToggled property, you’ll see that the property switches between true/false values.  WPF is keeping track of the “toggled” state for the ‘a’ key, even though it’s not normally used as a toggle key.

        private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
            Trace.WriteLine(string.Format("----- PreviewKeyDown for key {0}, toggled = {1}", e.Key, e.IsToggled));


About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

One Response to #647 – You Can Treat Any Key As A Toggle Key

  1. Pingback: Dew Drop – September 14, 2012 (#1,401) | Alvin Ashcraft's Morning Dew

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: