KeyChar WPF

Hi. I use to use this way to let user enter only characters I allowed  to text box
 if (e.KeyChar >= 97 && e.KeyChar <= 102) //a b c d e f
            {
                e.Handled = false;
            }

            if (e.KeyChar >= 65 && e.KeyChar <= 70) // A B C D E F
            {
                e.Handled = false;
              }
But this is not working with WPF.
How can I do that?
LVL 1
mastiSoftAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MishaProgrammerCommented:
Try something like this:

		private void Textbox1_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.Key >= Key.A && e.Key <= Key.F)
			{
			}
			else
			{
				e.Handled = true;
			}
		}

Open in new window


XAML code:
<TextBox Name="Textbox1" HorizontalAlignment="Left" Height="23" Margin="364,69,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" KeyDown="Textbox1_KeyDown" />

Open in new window


It allow to input key A B C D E F

If you want to allow user input other keys, use this:
			if (e.Key <= Key.A && e.Key >= Key.F)
			{
				
			}
			else
			{
				e.Handled = true;
			}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mastiSoftAuthor Commented:
thank you again ).
MishaProgrammerCommented:
Glad to hepl you!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
WPF

From novice to tech pro — start learning today.