Forum Xamarin.Forms

Tailwind Traders TwoProductItemTemplate Binding

Hi! I've been going through the Tailwind Traders app, examining their code and learning a bunch, attempting to replicate a lot of their stuff to gain the experience. I'm currently stuck on how they're databinding their ProductView XAML to their ProductViewModel? I notice in the codebehind for the ProductCategoryPage in their WireProductsUpWithListView method that they are merely setting their ListView's source to basically a list (tuple) of ProductViewModels.

I similarly have a ListView that is successfully binding to my custom ItemTemplate, and I even get each item to show in the ListView, the data isn't being bound however.

I have a feeling it lies in their ItemTemplate, the code I'm having a hard time understanding:

  <local:ProductView BindingContext="{Binding Item1}" />

    BindingContext="{Binding Item2}"
    IsVisible="{Binding ., Converter={StaticResource IsNotNullConverter}}" />

I understand this is just for creating 2 columns of ProductView, and an empty space for if there is an odd number, but I cannot for the life of me figure out how they are BindingContext = "{Binding Item1}". I can't figure out what exactly that Item1 or Item2 is, I have searched the entire solution for what it's binding to, with no luck. From my understanding, shouldn't their BindingContext's be to the ProductViewModel? I haven't managed to find anything substantial online for this kind of binding, unless I suck at Google haha, any help would be appreciated!


  • Timothy_RichTimothy_Rich Member ✭✭
    edited December 2018

    To clarify what I'm asking, my use case is as follows:

    My app calls a service that returns a list of object's from a remote database. The number of objects in that list changes drastically from 0 - 500. I would like to present those objects in the form of some custom card view that I hand make using a Data template. Just like the Tailwind Traders app. Each object has a subsequent ViewModel because the ViewModel holds multiple Command's and specialized properties that change from object to object. I'm correctly creating those ViewModels for each object, and my ListView is correctly binding it's ItemTemplate to my custom card view, but the data is never bound. It just holds values that I hard code like "Object ID: {object.Id}", but the Id is never bound.

  • jezhjezh Member, Xamarin Team Xamurai

    Have you got the answer?

  • Timothy_RichTimothy_Rich Member ✭✭


    Not yet! I feel like I have tried everything, but cannot get it to bind correctly! It's a breeze with the code behind approach, simply creating a list of card views based on my list of objects, and then assigning those views to my listview. Works like a charm, but I would really like it to be based on MVVM, it just doesn't work though!

Sign In or Register to comment.