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

Best way to pass data from code-behind to view model when using strict MVVM

$
0
0

Scenario:
I'm using a barcode scanner API in my view which seems to require me to hook up an event in the code-behind file as the only way to get the scanned barcode. When the barcode is scanned I want to pass the data on to the view model but since I want to follow the MVVM pattern I don't want a reference to the view model from my code-behind.

Right now I solved it by using the built in MessagingCenter.
Since the subview is showing within another view, there is no navigation taking place where I can pass on data from one vm to another.

Question:
Is MessagingCenter the best solution for this?

Sub question:
What is the best way to pass data between two view models for views showing at the same time (no navigation occurs)? I'm using MessagingCenter for this too right now.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



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