Tlink
Tlink

Reputation: 913

Xamarin.Forms bindingContext in MVVM

Further to This Question regarding BindingContext

I'm looking at a Xamarin.Forms project that implements MVVM , when I look into a XAML page, for example SomePage.xaml and I want to find the ViewModel that has the logic for that page, it's usually a hit and a miss.

In simpler Xamarin.Forms applications I would just look into SomePage.xaml.cs to see the bindingContext.

But it seems in a bigger app this is "Abstracted Somewhere"

For example in SomePage.xaml I see :

x:Class="MyApp.SomePage"

But this is usually not the class containing the code, it seems to be the code representation of the XAML file

I had more luck when I search for SomePageViewModel.cs, but not all the time.

Searching for the term bindingContext in the code yielded no results.

My question is where else can I look for bindingContext , to determine what classes contains the code controlling the XAML pages.

It seems that this is abstracted in some way because I see in the code BindableBase .

Upvotes: 0

Views: 291

Answers (1)

Jason
Jason

Reputation: 89102

from the PRISM docs

prism:ViewModelLocator.AutowireViewModel="True"

This view (MainPage.xaml) is wired to the view model (MainPageViewModel.cs) automatically via naming conventions allowing for databinding to the view model. See ViewModelLocator documentation for more information.

and

Within the Portable project there is a ViewModels folder. This folder will contain all of your view model related code. The template created a view model for the MainPage called MainPageViewModel.cs in this folder. Lets take a look at this class and break down what is going on here.

Upvotes: 1

Related Questions