15mgm15 / consume-a-json-api-using-xamarin.forms Goto Github PK
View Code? Open in Web Editor NEWExample of consuming a JSON API using Xamarin.Forms
Example of consuming a JSON API using Xamarin.Forms
Hi,
I´m working on an app and I tried to replicated and everything works until my service returns 404 error.
The service throw the exception to ViewModel. The ViewModel throw the exception to View and the View displays the error returned from API.
After that, I swipe down to refresh the page and the code in ViewModel is not executed.
This is the constructor code in View class:
`
public Menu()
{
InitializeComponent();
try
{
this.token = PropertiesOperations.GetTokenProperties();
//show Name
if (this.token.FullName != null)
lblFullName.Text = "Ing. " + this.token.FullName;
BindingContext = viewModel;
viewModel = new ProjectViewModel(this.token.UserIDCRM);
}
catch (Exception ex)
{
Device.BeginInvokeOnMainThread(async () =>
{
await this.DisplayAlert("Error", ex.InnerException.Message, "OK");
});
}
}`
This is XAML code:
<StackLayout Orientation="Vertical"> <StackLayout Orientation="Horizontal" Margin="0,0,0,50"> <Label HorizontalTextAlignment="Center" x:Name="lblFullName" HorizontalOptions="CenterAndExpand" FontAttributes="Bold" TextColor="Black" FontSize="16"/> </StackLayout> <ListView x:Name="ProjectsList" ItemsSource="{Binding ProjectsList}" ItemTapped="ListView_ItemTapped" IsPullToRefreshEnabled="true" RefreshCommand="{Binding RefreshCommand}" IsRefreshing="{Binding IsRefreshing}"> <ListView.ItemTemplate> <DataTemplate> <TextCell Text="{Binding idProject}" Detail="{Binding description}" TextColor="Black"></TextCell> </DataTemplate> </ListView.ItemTemplate> </ListView> <ActivityIndicator HorizontalOptions="Center" x:Name="actLoading" IsVisible="{Binding IsRefreshing}" IsRunning="{Binding IsRefreshing}" Color="#1360ad"/> </StackLayout>
It's weird. If the API returns data everything works perfectly.
Have you ever have any situation like this?
Thanks so much!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.