C
C#3w ago
Zoli

Why deletion of last character in Entry not triggers observableProperty? (MVVM, Maui)

I have an input field where the user can enter numbers. When any number is typed, the model updates successfully, which I can confirm using a breakpoint. However, when there is only one character left and it is deleted, the update does not occur, and the model retains the previous number instead of updating. Why is this happening, and how can I ensure the model updates correctly when the last character is deleted? ViewModel
private int _value;

// TODO when delete the last value, it should trigger to set the model value
partial void OnValueChanged(int value)
{
_model.Value = value;
}
private int _value;

// TODO when delete the last value, it should trigger to set the model value
partial void OnValueChanged(int value)
{
_model.Value = value;
}
Xaml <Entry Keyboard= "Numeric" Text= "{Binding Value}" />
2 Replies
ACiDCA7
ACiDCA73w ago
what should the value be set to? your property isnt nullable, so the onpropertychanged wont be thrown becaue validation fails. sadly im not too familiar what maui provides for this case there is always the possibility to make the property a string instead and to do validation/parsing yourself
Zoli
ZoliOP3w ago
Originally I had int?, but with that also was the same case. I changed to string and add a parser with that when the last "number" is deleted it triggers as expected.

Did you find this page helpful?