dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
6.93k stars 1.15k forks source link

Problem Bingding with VNI Telex #9248

Open phanthanhdat077 opened 1 month ago

phanthanhdat077 commented 1 month ago

I can not binding to Text from TextBox my Text property always empty when I using VIE Vietnamese Telex from Keyboard layout Win 11 image

image

image

WpfApp14.zip

lindexi commented 1 month ago

@phanthanhdat077 Can it work well with other IME?

I can not repro your issues with Microsoft Pinyin.

phanthanhdat077 commented 1 month ago

I don't know too I don't use Microsoft Pinyin (I tried to use Microsoft Pinyin it can type numbers and binding to my Text but Vietnamese Telex still can not binding). Do you have any suggestions to fix it with Vietnamese Telex? My way is not to use Vietnamese telex again

@phanthanhdat077 Can it work well with other IME?

I can not repro your issues with Microsoft Pinyin.

lindexi commented 1 month ago

@phanthanhdat077 Sorry, I don't know anything about Vietnamese Telex right now

miloush commented 1 month ago

If it helps to investigate, note that Vietnamese Telex is IME. The view model property is not getting updated until the composition is committed. It does seem to be reflected in the TextBox.Text property though on every TextChanged event.

lindexi commented 1 month ago

@miloush What I'm confused about is why is the TextChanged event triggered but the Text is empty.

miloush commented 1 month ago

As I said, the databinding does not update the Text property. The Text is only empty on the viewmodel, not on the TextBox. I would guess that the composition events do not change the TextBox.Text property in a way that a databinding with PropertyChanged trigger would pick it up.

phanthanhdat077 commented 1 month ago

As I said, the databinding does not update the Text property. The Text is only empty on the viewmodel, not on the TextBox. I would guess that the composition events do not change the TextBox.Text property in a way that a databinding with PropertyChanged trigger would pick it up.

yes, TextBox.Text still received the text I just can not binding to ViewModel.

miloush commented 1 month ago

Your viewmodel will get the text once the input is committed, e.g. after typing a space. This applies to all similar IMEs, not only Vietnamese Telex. It does feel like a bug that the TextBox is firing TextChanged but not the DP value change. I am a bit busy at the moment to have a closer look, perhaps others can give it a go.

phanthanhdat077 commented 1 month ago

my problem: I using Textbox for typing only numbers and can't space that method for payment it has the event TxtInputMoney_PreviewTextInput to handle for type only numbers but when I turn on Vietnamese Telex it can overcome the event TxtInputMoney_PreviewTextInput and type the word.

private void TxtInputMoney_PreviewTextInput(object sender, TextCompositionEventArgs e) { Regex regex = new Regex("[^0-9]+"); e.Handled = regex.IsMatch(e.Text); }