Is there any built in local number to int converter?

Emon Haque 3,176 Reputation points
2021-06-29T15:18:31.797+00:00

This is the first time I'm using my language in WPF and it actually is very easy to use and looks nice:

110277-test.gif

For date and numbers in the listbox/datepicker I don't have to do anything, it's automatically converted from/to the Thread Culture BUT for number in the TextBox I've to convert since I use avro phonetic keyboard. I've found this function on the web:

bool gotEnglish(string value) {  
    var nativeDigits = CultureInfo.CurrentCulture.NumberFormat.NativeDigits;  
    var text = value.ToString()  
                .Replace(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator, ".")  
                .Replace(nativeDigits[0], "0")  
                .Replace(nativeDigits[1], "1")  
                .Replace(nativeDigits[2], "2")  
                .Replace(nativeDigits[3], "3")  
                .Replace(nativeDigits[4], "4")  
                .Replace(nativeDigits[5], "5")  
                .Replace(nativeDigits[6], "6")  
                .Replace(nativeDigits[7], "7")  
                .Replace(nativeDigits[8], "8")  
                .Replace(nativeDigits[9], "9");  
    int num;  
    var result = int.TryParse(text, NumberStyles.Integer, CultureInfo.InvariantCulture, out num);  
    if (result) NewRegion.Quantity = num;  
    return result;  
}  

and it works fine. Is there any built in converter like BooleanToVisibilityConverter or some other way to convert local number input into int?

One more issue with Date format. In the ListBox on the right, I've specified StringFormat='dd MMM yyyy' for the date column in the middle and the first two months January (জানু) and February (ফেব) are shortened but rest are actually full name.

EDIT
----
I've only one language on the machine:

110484-capture.png

and when I type numbers in TextBoxes, it automatically converts those numbers into my language and when I click চালু Button, those numbers and date are converted into Enlish so I don't need any phonetic keyboard for numbers or function for int conversion BUT when I type non-numeric characters, it doesn't get converted into my locale automatically:

110448-test2.gif

EDIT
----
Producing local number without that language installed on the machine is kind of inconsistent. I've tried the bn-BD language pack provided by MS:

110767-test3.gif

BUT it doesn't have any phonetic keyboard, who knows what that INSCRIPT keyboard is! With that in my machine now when I switch language by hitting Windows + Space, it produces Bangla in all TextBoxes and I don't have to convert those numbers manually with that conversion function:

110698-test4.gif

Phonetic keyboard for bn-BD is required. Most of us, nowadays, don't use Bijoy, Ekushe, etc. or the cryptic INSCRIPT you provide with the language pack. I use Avro in windows and also used OpenBangla in Linux, those are same, that's what I/we use.

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,710 questions
0 comments No comments
{count} votes