Armando Alvarez
Armando Alvarez

Reputation: 75

How can I access data from code behind to MVVM

I have this data in code behind

public partial class PruebaPage : ContentPage
{
    public string Datas { get; set; } // data that I want to access

and this is my View Model

namespace PuebasTemplate.ViewModels
{
    public class PruebaViewModel : INotifyPropertyChanged

Is there some way to access public string Datas from my MVVM PruebaViewModel?

Upvotes: 1

Views: 458

Answers (1)

BradleyDotNET
BradleyDotNET

Reputation: 61339

Is there a way? Sure. The page could pass itself into the VM via some method or property for one.

But you shouldn't do that

View models are not supposed to know anything about their view, certainly not the tight coupling of having an actual reference to it. Sounds like you have an XY problem; and that data should live in the view model to start with.

Upvotes: 2

Related Questions