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

Xamarin.Forms use MessagingCenter with Login method

$
0
0

My app is a Xamarin.Forms PCL app using Profile 259. I'm trying to send a message to the user if the login fails due to a user name or password error. If the login fails, a catch block in the SignInViewModel is invoked. The catch block is posted below. I would like to send a message to the user if the catch block occurs. Here is my current code. I can't get this to display the message.

 catch (Exception ex)
            {
                // Log error in Xamarin.Insights
                Insights.Report(ex, Insights.Severity.Error);

                // Send message to inform user that Sign In failed                
           //MessagingCenter.Send(this, "SignInFailed");

          string sentMessage = null;

          MessagingCenter.Subscribe<SignInViewModel, string> (this, "SignInFailed", (sender, args) => sentMessage = args); 

          MessagingCenter.Send (this, "SignInFailed", "Login failed. Please check your user name and password."); 

          //Assert.That (sentMessage, Is.EqualTo ("My Message")); 

          sentMessage = ("Login failed. Please check your user name and password.");

          MessagingCenter.Unsubscribe<SignInViewModel, string> (this, "SignInFailed"); 

              return;
            }

If the password or user name is missing, I send a toast notification and that is working. The toast notification uses an await parameter, so I can't use it in the catch block.

Any help is much appreciated. Thanks!


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>