简体   繁体   中英

Windows phone update listview

I created a Windows phone 8.1 application with a listview on Startpage.xaml. When I update listview values, I don't see the changes on the phone until I close and open the application again. I tried to update the listview when I clicked the refresh button, but unsuccessfully. Anyone know how to update a listview when I click the refresh button?

How I fill in data in the listview:

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;

}

My class:

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; }
}

Refresh button:

    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;
    }

I also tried to refresh like this, but unsuccessfully:

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

To update the view you need to update the binding to ItemSource:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM