.NET MAUI MVVM: Capturing Updated Values in ViewModel with ReturnCommand on Entry Field Exit

122 Views Asked by At

I am developing an application in .NET MAUI using the MVVM pattern . My goal is to perform calculations automatically when the user exits an Entry field, without the need for an additional button press. To achieve this, I have bound the ReturnCommand of each Entry to a command in my ViewModel, but I am not receiving the updated value of the bound property in the command when the user changes fields.

Here is my implementation:

<Entry Placeholder="Cantidad Cajas"
       Text="{Binding NumberBoxBuy, Mode=TwoWay}"
       ReturnCommand="{Binding EntryCompletedCommand}"
       ClearButtonVisibility="WhileEditing"/>

My viewModels

[ObservableProperty] 
public int numberBoxBuy;

[RelayCommand]
private async Task EntryCompleted()
{
    Console.WriteLine($"Number entered: {NumberBoxBuy}");
}
0

There are 0 best solutions below