I'm creating an options dialog using WPF that lists possible keys so that the user can assign the program's hotkey. I'm attempting to filter all of the possible values of the System.Windows.Forms.Keys enumeration down to just A-Z and F1-F12, and then bind that list to a ComboBox.
Here's my code so far:
Regex filter = new Regex("(^[A-Z]$)|(^F[0-9]{1,2}$)");
IEnumerable<Key> keyList = from x in (IEnumerable<Key>)Enum.GetValues(typeof(Keys))
where filter.Match(x.ToString()).Success
select x;
keys.DataContext = keyList;
After executing this, keyList contains the letter "A" twice and is missing letters "P" through "U." I'm at a loss as to why.
I'm also interested in alternate approaches, if there's a better way.