Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Form validation with Exception handling using MVVM and Commands needed

$
0
0

I'm looking for a real world sample application that uses MVVM with Xamarin.Forms that binds to a Command which calls a service to update some data and then have MVVM command handle any exceptions. Whew!

Here's a better idea of the flow of what I'm looking for, it's fairly simple:

It's a Login form, but the concept will be applied to other input forms I will have:

1) The user clicks the Login button without entering credentials
2) The Login button is bound to a ViewModel with a Command property called: viewModel.LoginAsync()
3) This ViewModel Command property LoginAsync() makes a call to an AuthService called: _authService.AuthenticateUserAsync(Username, Password) which will validate the input and throw an exception for bad or invalid input.

I've tried many different iterations to catch the exception and display an alert, but I know I can't and probably shouldn't show the alert from the ViewModel, so I'm trying to figure out how to bubble up the AggregateException back to the UI Click event.

My code works if valid data is entered, but any exception seems to slip right through my Exception handling and gets caught by the garbage collector and then crashes the app.

I've looked at the FieldService app and I can just glean how it works, but there doesn't seem to be validation for bad input. I also can't run the app since there's 3848 errors in 98 files, and this is after I restored the NuGet packages.

Any help and suggestions is appreciated.


Viewing all articles
Browse latest Browse all 58056

Trending Articles