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

Best way to execute code in the viewmodel from an UI event.

$
0
0

I have a simple data entry page called NewCustomerPage that's bound to a viewmodel called NewCustomerViewModel like so:

public partial class NewCustomerPage : ContentPage
{
    public NewCustomerViewModel _newCustomerViewModel;

    public NewCustomerPage()
    {
        InitializeComponent();

        _newCustomerViewModel = new NewCustomerViewModel();
        this.BindingContext = _newCustomerViewModel;
    }
}

Inside the page there's a series of text fields bound to an object property Customer in the viewmodel. What I need to do is save said object in a database and this is where I'm having issues. If Customer was inside of the page I could simply put the code inside of the event raised when clicking a button on the UI and be done with it. With the object residing in the viewmodel, though, I need a way to invoke said code from the UI.

From my readings I suspect I need to use one of the two between a Command or the Messaging Center. Am I right? Is this the best approach to my necessities?


Viewing all articles
Browse latest Browse all 91519

Trending Articles



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