Я все еще учусь, поэтому, пожалуйста, потерпите меня.
Я пытаюсь отобразить ListView
в моем Xamarin.Form
.Пока что это то, что у меня есть, и оно работает довольно хорошо:
<?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:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps"
xmlns:local="clr-namespace:GasStations"
x:Class="GasStations.MainPage">
<StackLayout>
<ListView x:Name="ListView_Pets">
</ListView>
</StackLayout>
</ContentPage>
Это код:
var obj = JsonConvert.DeserializeObject(coord);
List<String> storeList = new List<String>();
string store = string.Empty;
foreach (var item in ((JArray)obj))
{
store = item.Value<string>("name");
//desc = item.Value<string>("description"); /* This is the string I want to display */
storeList.Add(store);
}
ListView_Pets.ItemsSource = storeList;
Работает и показывает имена магазинов в ListView
.Вы можете увидеть скриншот здесь .
Теперь вместо того, чтобы просто показывать магазин Name
в ListView
, я хочу также отобразить описание (и любые другие значения).Я предполагаю, что мне понадобится Labels
в каждом ряду, аналогично asp.net
GridView
ItemTemplate
.
Я пробовал что-то подобное, но это не компилируется:
<?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:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps"
xmlns:local="clr-namespace:GasStations"
x:Class="GasStations.MainPage">
<StackLayout>
<ListView x:Name="ListView_Pets" ItemsSource="{Binding MyClass}" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<Label x:Name="Label_Name" Text="Name" />
<Label x:Name="Label_Desc" Text="Description" />
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>
У меня есть доступ к Name
и Description
в коде позади (с desc = item.Value<string>("description");
, ноЯ не знаю, как связать эти значения с метками в форме.