Search code examples
c#wpfinternationalizationtextboxmaxlength

MaxLength on WPF app does not work for Korean Language


I'm having trouble trying to get the MaxLength property of a TextBox in WPF to work when I'm using a on screen keyboard with Korean language.

It just doesn't limit and also it won't give me any event other than TextChanged, so I didn't find a way to avoid the character being written on the screen.

Also, if i try to just remove the character just after being inserted and change the caret position to the end, the app just crashes without any exception during debugging.

I would really appreciate if you have any ideas on how could I fix it!

Thanks!!


Solution

  • 1st,

    textbox.PreviewTextInput += textbox_PreviewTextInput;
    
    void textbox_PreviewTextInput(object sender, TextCompositionEventArgs e)
    {
       TextBox box = (TextBox) sender;
       e.Handled = box.Text.Length > 5;
    }
    

    2nd, post a bug to MS Connect

    3rd, enable all exceptions Debug-Exceptions, then maybe not JustMyCode in options to see what happens.