CommunityToolkit / CommunityToolkit/MVVM-Samples
How to work with nullable properties?
- Dominant language
- No language data
- Stars
- 1.4k
- Forks
- 265
- PR merge metrics
- No merged PRs in 30d
Description
I have a Textbox that binds to a long? property in the view model.
I would like that if the TextBox is empty, to set the value of the property to null. But when the TextBox is empty, the property in the view model is not changed, it keeps the last digit that the TextBox had.
I would like to have null when the TextBox is empty.
I was trying to intercept the prperty changed event in this way:
```
[ObservableProperty]
long? _myProperty;
partial void OnMyPropertyChanging(long? value)
{
Console.WriteLine($"Name has changed to {value}");
_myproperty = value;
}
```
However the behaviour is not very good. When I write this secuence in the TextBox I get this behaviour:
1.- Write 5. I get 5 as value.
2.- Delete 5, the method is not execute
3.- Write 5, the method is not execute
4.- Write 5, the value of the method is 55
How could I bind to a long? property?
Thanks.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.