title: Best practice for choosing handler or command for the button in Xamarin.Forms
body: <p>I'm new in Xamarin. By learning the MVVM pattern, I've got the idea for mapping button with commands, and deal with logical things in viewmodel.</p>
  
  <p>Then scenarios changed. 
  When I was developing some Login functionalities for the mobile app, I need to call <strong>"DisplayAlert"</strong> or <strong>"pop"</strong> or <strong>"push"</strong> when clicking the button.</p>
  
  <p>I checked some forums and blogs to see how to solve, listed as below:</p>
  
  <ol>
  <li>pass the navigation as a parameter, like <a href="https://forums.xamarin.com/discussion/21822/call-navigation-pushasync-from-viewmodel" rel="nofollow noreferrer">this thread</a>, or even use injection in the same thread;</li>
  <li>use NuGet packages like <a href="https://github.com/aritchie/userdialogs" rel="nofollow noreferrer">userdialogs</a></li>
  <li>use handler like <a href="https://developer.xamarin.com/samples/xamarin-forms/Navigation/LoginFlow/" rel="nofollow noreferrer">Microsoft docs</a>, (so I assumed that it is acceptable to use handler in simple navigation).</li>
  <li>add some message text in viewmodel class and mapping to some entries on the view, but this cannot solve the conflict when it is required for a dialog box or navigation.</li>
  </ol>
  
  <p>So is this question supposed to change to "how to choose button implementation, handler or command"? </p>
  
  <p>But again, "handler" is not recommended by MVVM. Now I am confused. </p>
  
  <p>Any advice will be helpful. </p>
  
  <p>Cheers.</p>