2015-05-12 38 views
3

我在Startpage.xaml上創建了一個帶有列表視圖的Windows Phone 8.1應用程序。當我更新listview值時,在關閉並再次打開應用程序之前,我看不到手機中的更改。我試圖在點擊刷新按鈕時更新列表視圖,但未成功。當我點擊刷新按鈕時,任何人都知道如何更新列表視圖?Windows手機更新列表視圖

我如何填寫數據的列表視圖:

protected async override void OnNavigatedTo(NavigationEventArgs e) 
{ 
    this.navigationHelper.OnNavigatedTo(e); 
    HttpClient http = new HttpClient(); 
    string str = ((ComboBoxItem)cbox.SelectedItem).Content.ToString(); 
    var response = await http.GetStringAsync("http://mywebpage.si/events/apis/facebook_events.php?city=" + str + "&user=" + uporabnik.user); 
    var FSfeed = JsonConvert.DeserializeObject<List<Class1>>(response); 

    Reviews.ItemsSource = FSfeed; 

} 

我的類:

public class Class1 
{ 
    public string title { get; set; } 
    public string description { get; set; } 
    public string image { get; set; } 
    public string start { get; set; } 
    public string end { get; set; } 
    public string location { get; set; } 
    public string city { get; set; } 
    public int id { get; set; } 
} 

刷新按鈕:

private async void refresh_Click(object sender, RoutedEventArgs e) 
    { 
    HttpClient http = new HttpClient(); 
    string str = ((ComboBoxItem)cbox.SelectedItem).Content.ToString(); 
    var response = await http.GetStringAsync("http://mywebpage.si/events/apis/facebook_events.php?city=" + str + "&user=" + uporabnik.user); 
    var FSfeed = JsonConvert.DeserializeObject<List<Class1>>(response); 

    Reviews.ItemsSource = FSfeed; 
    } 

我也嘗試刷新這個樣子,但不成功:

private async void refresh_Click(object sender, RoutedEventArgs e) 
    { 
     this.Frame.Navigate(typeof(PivotPage)); 
    } 
+0

是在* *的ListView與項目首次填寫正確?也許這是* http.GetStringAsync *中緩存*響應的問題 - 在這種情況下,它將被刷新,但具有相同的數據。 – Romasz

+0

您是否嘗試調試並檢查您在點擊刷新時是否接收到另一組數據? –

+0

您是否嘗試將列表視圖切換爲可觀察集合。模型視圖視圖模型設計模式可能是一個有用的方法。 –

回答

0

要更新需要更新的結合的ItemSource的觀點:

List<Class1> mySource = new List<Class1>(); 
Binding binding = new Binding { Source = mySource }; 
BindingOperations.SetBinding(myListView, Windows.UI.Xaml.Controls.ListView.ItemsSourceProperty, binding);