Click here to Skip to main content
15,747,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I'm using wpf c# in visual studio i want to prevent user can enter Arabic character , Just Persian Character

like when user entered this value on keyboard → "ي" change it to "ی"

my means something like this : when user press button to type "A" on keyboard i want to change this character, first check if is "A" change to "B"

i did it in Windows Form Application , but that code does not work in WPF

My Code in Windows From :

if (e.KeyChar.ToString() == "ي")
                e.KeyChar = Convert.ToChar("ی");

My Code in WPF :

if (e.Key.ToString() == "ي")

These codes not working in WPF

Please Help

What I have tried:

if (e.KeyChar.ToString() == "ي")
                e.KeyChar = Convert.ToChar("ی");

i test this in wpf but did't work
Updated 6-Oct-20 5:37am

1 solution

"Swallow" the Key you don't want (e.Handled = true), then "send" the Key you want in its place.

WPF – Send keys | michlG's Blog[^]
Share this answer
Member 13707743 6-Oct-20 14:55pm    
thanks but its not working for change character entered Arabic to Persian

ی → ي

! ؟
Member 13707743 6-Oct-20 15:01pm    
I don't want to send key
i want change character entered

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900