Forum Xamarin.Forms

BindingContext: use the same resource for a datatemplate and a contentview

CalebSkinnerCalebSkinner USMember ✭✭
edited July 2020 in Xamarin.Forms

I've got a challenge with binding context. I've got a listview that has a template selector. The template selector uses different data templates based on the data that is being displayed. The bindingcontext looks something like <label Text="{Binding Name}"/>. This works well. I would now like to use the same data template in a contextview to populate the ControlTemplate. The layout renders correctly. The bindingcontext looks something like <label Text="{TemplateBinding BindingContext.Name}"/>. This also works. However, I have to change the way the bindingcontext is specified. Is there away to use the same data template between both the listview and the contentview without changing the bindingcontext? I'm trying to avoid having the same layout twice to support different bindingcontext styles.

Thanks!

Best Answers

  • CalebSkinnerCalebSkinner USMember ✭✭
    Accepted Answer

    This worked. I had to create a datatemplete and have that point to the resource. My previous code had the template selector for the listview pointing directly at the resource. All good! Thanks

Answers

  • CalebSkinnerCalebSkinner USMember ✭✭
    edited July 2020

    Just figured out how to edit...

  • CalebSkinnerCalebSkinner USMember ✭✭

    I'll implement and update with the results tomorrow. Thanks!

  • CalebSkinnerCalebSkinner USMember ✭✭
    Accepted Answer

    This worked. I had to create a datatemplete and have that point to the resource. My previous code had the template selector for the listview pointing directly at the resource. All good! Thanks

Sign In or Register to comment.