Reputation: 5
Json
[
{
"_id": "5a6736a55c720e4593f74236",
"indigentApplicationDetails": {
"conditionsDetail": {
"foodDetail": {
"rating": {}
},
"clothingDetail": {
"rating": {}
},
"medicalDetail": {
"rating": {}
},
"shelterDetail": {
"rating": {}
}
},
"householdDetail": [
{
"currentApplicationRefNo": "1000048573",
"personDetail": {
"gender": "Male",
"surname": "Khabanya",
"initials": "S G",
"genderDisplay": "Male",
"personID": "125555",
"firstNames": "Siphiwo Gift",
"title": "37",
"relationship": "Other",
"titleDisplay": "Mr",
"idNo": "6706115835080",
"birthDate": "1967-06-11 00:00:00"
},
"incomeDetail": {
"amount": "0",
"budgetDetail": {
"otherIncome": "0",
"totalPersonIncome": "0",
"accountHolder": "true",
"propertyRenting": "0",
"uif": "0",
"previousWorkPension": "0",
"homeBusiness": "0.0",
"oldAgePension": "0",
"disabilityPension": "0.0"
}
},
"workSituationDetail": {
"skillCurrentDetail": {
"skillDetail": {}
},
"employmentDetail": {},
"skillDesiredDetail": {
"skillDetail": {}
},
"workDuration": "0"
},
"healthDetail": {
"mentalDefect": "false",
"disability": "false",
"poorHealthDetails": "0"
}
}
]
ListView
<ListView
HasUnevenRows="True"
ItemsSource="{Binding ItemsSource}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label TextColor="White" Text="{Binding IndigentApplicationDetails.householdDetail.currentApplicationRefNo}"/>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Code
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
BindingContext = new IndigentDetailsViewModels();
}
protected override async void OnAppearing()
{
base.OnAppearing();
await (BindingContext as IndigentDetailsViewModels)?.LoadData();
}
}
class IndigentDetailsViewModels : INotifyPropertyChanged
{
private List<IndigentApplicationDetails> _indigentDetails;
public List<IndigentApplicationDetails> IndigentDetails
{
get { return _indigentDetails; }
set
{
_indigentDetails = value;
OnPropertyChanged(nameof(IndigentDetails));
}
}
public IndigentDetailsViewModels()
{
_indigentDetailsServices = new indigentDetailsServices();
}
readonly indigentDetailsServices _indigentDetailsServices;
public async Task LoadData()
{
IndigentDetails = await _indigentDetailsServices.GetIndigentDetailsAsync();
}
public event PropertyChangedEventHandler PropertyChanged;
// [NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
class indigentDetailsServices
{
HttpClient client = new HttpClient();
public async Task<List<IndigentApplicationDetails>> GetIndigentDetailsAsync()
{
try
{
var response = await client.GetStringAsync("https://munipoiapp.herokuapp.com/api/applications/New/KemptonMobileward1");
var IndigentDetails = JsonConvert.DeserializeObject<List<IndigentApplicationDetails>>(response);
return IndigentDetails;
}
catch (System.Exception exception)
{
return null;
}
}
}
class IndigentApplicationDetails
{
public int currentApplicationRefNo { get; set; }
}
Upvotes: 0
Views: 619
Reputation: 3698
There are a few reason why you're not seeing anything on your screen:
You're using ItemsSource="{Binding ItemsSource}"
but there is no such property named ItemsSource
in your IndigentDetailsViewModels
. You should bind IndigentDetails
.
Text="{Binding IndigentApplicationDetails.householdDetail.currentApplicationRefNo}"
should be Text="{Binding currentApplicationRefNo}"
.
Most platforms have white background color for cell. If you make your text color white it will be invisible.
Upvotes: 1
Reputation: 144
please check below xaml code and check it it would be sure work for you
<ListView HasUnevenRows="True" ItemsSource="{Binding IndigentDetails}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="10">
<Label Text="{Binding currentApplicationRefNo}"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Upvotes: 0