indubitablee
indubitablee

Reputation: 8206

Xamarin Forms ListView Data Binding

ObservableCollection<string> CompanyList in the xaml.cs code behind is tied to <ListView> element in the xaml. Left alone, it displays a list of the strings in CompanyList as expected.

However, I want to customize (purely for style purposes) the ViewCell in the ListView while leaving CompanyList as a collection of strings. I am unsure how to bind the string company list value.

    <ListView x:Name="CompanyList" ItemTapped="OnAddCompanyFilterTapped" >
      <ListView.ItemTemplate>
        <DataTemplate>
          <ViewCell>
            <StackLayout Padding="0" Spacing="0">
              <StackLayout  Padding="10">
                <Label Text="{Binding ??????????}" HorizontalOptions="Fill"/>
              </StackLayout>                  
              <BoxView Style="{StaticResource divider}"/>
            </StackLayout>                
          </ViewCell>
        </DataTemplate>
      </ListView.ItemTemplate>
    </ListView>

What do I put in the ??????? to get the string in CompanyList to show?

Any help/suggestions/ideas is greatly appreciated!

Upvotes: 2

Views: 2076

Answers (1)

Mark Larter
Mark Larter

Reputation: 2363

Binding Path=. should do it, which can be shortened:

<Label Text="{Binding}" HorizontalOptions="Fill"/>

Assumes the ListView.ItemsSource remains CompanyList.

Upvotes: 2

Related Questions