Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

BindingContext of ListView item does not point to the item

$
0
0

I have an issue with binding. Although I know what the issue is, I don't know how to fix it. To begin with, here's my trimmed XAML:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
             xmlns:atom="clr-namespace:AlbaasDevice.PresentationLayer.Controls.Atom;assembly=AlbaasDevice.PresentationLayer.Controls"
             x:Class="AlbaasDevice.PresentationLayer.HoursOfService.Views.HosRecap"
             prism:ViewModelLocator.AutowireViewModel="True"
             Title="Recap"
             >
  <ListView Margin="10" ItemsSource="{Binding Items}" HasUnevenRows="true" RowHeight="-1">
    <ListView.ItemTemplate>
      <DataTemplate>
        <ViewCell>
          <StackLayout Margin="0, 0, 0, 5">
            <atom:AccordionBar Text="{Binding Title}" />
          </StackLayout>
        </ViewCell>
      </DataTemplate>
    </ListView.ItemTemplate>
  </ListView>
</ContentPage>

What I want is for my {Binding Title} to fetch the Title property of my ListView item and give it to the Text bindable property of my AccordionBar. Although I thought this would work, it doesn't.

To make sure my item's Title property does have text, I added <Label Text="{Binding Title}" /> right before and I do see the text. So I thought of doing the following:

<Label x:Name="Buffer" Text="{Binding Title}" IsVisible="False" />
<atom:AccordionBar Text="{Binding Source={x:Reference Buffer}, Text}" />

...and that works perfectly but I shouldn't have to do this, so perhaps the issue must be the BindingContext. To verify this, I created a Title property in my AccordionBar control and the text appeared. That means that, for some reason, the binding context is pointing to my AccordionBar instance instead of the ListView item.

How do I force it back to the ListView item?


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>