简体   繁体   中英

How to update the ListView in pivot page after updation of data through xaml UI? [Windows Phone 8.1]

I'm using a Data Model and Observable Collection to display items in list view. The data stored in a JSON file are displayed in list view. When I add new item to the JSON file I'm successfully able to write that into the file and save. But the change is not reflecting in the Page that shows the list view.

I'm using Navigation_LoadState to load data at the time of application launch. I know INotifyPropertyChanged can do the trick. But don't know how to and where to implement that in order to update the list view. Thanks in advance for your reply.

This is my JSON file that is used to bind the ListView at LoadState . Note that the "Members" only have 3 items

"Groups": [
    {
        "UniqueId": "Footballer",
        "Region": "Europe",
        "Country": "England",
        "Members": [
            {
                "UniqueId": "MANU",
                "Name": "Rooney",
                "JerseyNumber": "10",
                "Position": "Forward"
            },
            {
                "UniqueId": "CITY",
                "Name": "Aguero",
                "JerseyNumber": "16",
                "Position": "Forward"
            },
            {
                "UniqueId": "MANU",
                "Name": "Nani",
                "JerseyNumber": "7",
                "Position": "Midfielder"
            }
            ]
        }
    ]
}

And this is the JSON file after adding new item to the "Members" runtime via UI. Now the "Members" have 4 items .

{
"Groups": [
    {
        "UniqueId": "Footballer",
        "Region": "Europe",
        "Country": "England",
        "Members": [
            {
                "UniqueId": "MANU",
                "Name": "Rooney",
                "JerseyNumber": "10",
                "Position": "Forward"
            },
            {
                "UniqueId": "CITY",
                "Name": "Aguero",
                "JerseyNumber": "16",
                "Position": "Forward"
            },
            {
                "UniqueId": "MANU",
                "Name": "Nani",
                "JerseyNumber": "7",
                "Position": "Midfielder"
            },
            {
                "UniqueId": "CITY",
                "Name": "Yaya",
                "JerseyNumber": "5",
                "Position": "Midfielder"
            }
            ]
        }
    ]
}

How can I update this in my ListView . I'm using the item names Rooney , Aguero , Nani to bind with ListView.

It depends on the way you changing the items. If you replace the whole collection with a new one, implement INotifyPropertyChanged . But if you change the collection items (by adding\\removing\\replacing items), use ObservableCollection , XAML frameworks can automatically handle this.

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