2
votes

I have a ViewModel class which has a property of type String called Title.

In my View I have a ListView of type Comment. I would like to access the Title property of my ViewModel inside my ViewCell. Because the ViewCell has a different BindingContext I can't do this: '{Binding Title}'

Does anyone know how I can access my ViewModel property inside my ViewCell?

1
Have you tried bindings with source and path, like here? forums.xamarin.com/discussion/comment/144204/#Comment_144204 - Jauhenka
What are you trying to do with the Title? Are you trying to bind to it in the XAML for the ViewCell, or are you trying to access it when the item is tapped, etc? @Jauhenka's suggested link shows how to bind to another element (Binding Source Path), so you could bind to the ListView's DataContext to get access to the Title. - SmartyP

1 Answers

3
votes

I could be something like this:

<Label Text="{Binding Source={x:Reference this}, Path=BindingContext.Title}"></Label>

Where, the x:Reference is the page itself and it's being declared like this:

<ContentPage x:Name="this" ... >