Skip to content

Instantly share code, notes, and snippets.

@wirasetiawan29
Created October 11, 2014 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wirasetiawan29/15b0f661506b2cafe11e to your computer and use it in GitHub Desktop.
Save wirasetiawan29/15b0f661506b2cafe11e to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using mahasiswa.ViewModels;
namespace mahasiswa
{
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
LongListSelector_MainData_DataBind();
}
public async Task LongListSelector_MainData_DataBind()
{
try
{
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.GetAsync("http://128.199.145.197:3000/api/BERITA");
response.EnsureSuccessStatusCode();
if (response.IsSuccessStatusCode)
{
var mhs = response.Content.ReadAsAsync<IEnumerable<MahasiswaModel>>().Result.ToList();
LongListSelector_MainData.ItemsSource = mhs;
}
else
{
MessageBox.Show("Gagal");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void LongListSelector_MainData_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (LongListSelector_MainData.SelectedItem == null)
{
return;
}
PhoneApplicationService.Current.State["Berita"] = LongListSelector_MainData.SelectedItem;
NavigationService.Navigate(new Uri("/View/Detail.xaml", UriKind.Relative));
LongListSelector_MainData.SelectedItem = null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment