Forum Xamarin.Forms

Bind to a viewcell property from codebehind

DanneDanne SEMember ✭✭


I have a list where the ItemSource is a list of objects. Each of these objects has three properties, Id, Title and Description.

I also have a custom viewcell where I bind to the object properties in XAML as such:

                        <Label x:Name="NameLabel"
                               Text="{Binding Title}"/>
                        <Label x:Name="DescriptionLabel"
                               Text="{Binding Description}"/>

This is fine but now I want to access the Id value. How can this be done from my custom viewcell codebehind?

The way I do it now is not very elegant. I have a third Label like this:

                    <Label x:Name="IdLabel"
                           Text="{Binding Id}"

Now I can access the Id value from the IdLabel. But this seems a bit clunky. How can I get rid of the IdLabel and access the Id directly from my custom viewcell codebehind?

Best Answers


  • DanneDanne SEMember ✭✭

    Thank you for your answers. I've been putting off learning MVVM, hoping I'd be fine without it for my little project. But I guess it's better to buckle down and learn it properly.

    @JamesLavery, When clicking an item in the list, a detail page is opened for that selected item. I use the Id value to look up fields related to that item in the database.

Sign In or Register to comment.