Passing Variable Value From View to ViewModel

I have implemented a View Page that take photos and displaying them in a ListView.
To Upload the Photo to a web api, I'm storing the Path of Photos in a List filesPath.
Each time a photo taken, a file Path is added to the List filesPath.
I was be able to upload all photo by iterate to the filesPath list and upload each photo. This is done in code behind of the View.

Now, I'm trying to implement MVVM and have the ViewModel to handle the uploading task. Doing so, I would need to be able to access the ListfilesPath in the View from the ViewModel.
How would I be able to do that?
Also, Is this the right approach?

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    ListfilesPath in the View

    Stop. There's you're problem.
    Your view shouldn't have any variables. All your properties belong in the ViewModel when creating MVVM design pattern apps.
    The view is basically ignorant of everything. All it does is display binded properties from the VM>
    http://redpillxamarin.com/2018/03/12/2018-101-vs2017-new-solution/

  • ThinhTranCThinhTranC Member ✭✭

    That what I try to accomplish using MVVM pattern but unsure on how to approach, most of the examples I found demo on how to do MVVM is only with simple view, and example in taken photos is mostly done in code behind. I need some guidance/example on how to connect the dots. Do you have any example? A sample code is worth a millions word :smile:

    My view has a button take take photos, and photo will be added to a list view grid.
    The list view grid add photo to the grid on even of the photo is taken from the camera.
    How would I bind that from ViewModel to View?

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    I put a link to a series in the earlier post. I don't think you could have worked that series, built the sample app to learn the concepts etc. - in the 25 minutes between posts.

    Give the tutorial series I linked to you a real effort. It should teach you MVVM.

Sign In or Register to comment.