Created
October 11, 2014 09:57
-
-
Save wirasetiawan29/15b0f661506b2cafe11e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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