Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bind the values of the itemsource (array of strings) to a label in a ListView

I have an array of strings, that I have set as the item source of a ListView. The ListView now has the same amount of rows as the array has elements. However I don't know what to set the binding as. I know for a Dictionary I set 'Value' which works fine.

string[] array = {"1","2","3"};
MyListView.ItemsSource = array;

XAML

<ListView x:Name="MyListView">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <Label Text="{Binding Value, StringFormat='The value : {0:N}'}" />
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>
like image 417
james Avatar asked Mar 30 '17 19:03

james


2 Answers

If you want to bind directly to the value of the object itself, use the "." syntax for the path

<Label Text="{Binding .}" />
like image 79
Jason Avatar answered Nov 02 '22 00:11

Jason


To bind directly to the object you should use:

<Label Text="{Binding}" />

This is shorthand for:

<Label Text="{Binding Path=.}" />
like image 40
Harry Avatar answered Nov 01 '22 23:11

Harry