如何在ListView Windows Phone 8.1中更新ListViewItem

本文关键字:更新 ListViewItem Phone ListView Windows | 更新日期: 2023-09-27 17:57:28

我正在尝试更新ListViewItem中的文本,但找不到方法。

我修改了我使用的可观察集合,但ListView不会更新。我实现这一点的唯一方法是删除并添加相同的项目,但这会创建一个糟糕的动画(我删除了它,但它看起来也很糟糕)。

我的型号:

public class Feed : INotifyPropertyChanged
{
    public int idfeed { get; set; }
    public string message { get; set; }
    public string comments { get; set; }
    public string likes { get; set; }
    public string timestamp { get; set; }
    public string type { get; set; }
    public string iLiked { get; set; }
    public string next_id_comment { get; set; }
    public event PropertyChangedEventHandler PropertyChanged;
    public void NotifyPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
}

如何在ListView Windows Phone 8.1中更新ListViewItem

修改绑定到listviewitem的文本框的项(模型)的属性。确保包含该属性的模型实现INotifyPropertyChanged。

这样做:

    private string message;
    public string Message 
    {
        get
        {
            return message;
        }
        set
        {
               message = value;
               NotifyPropertyChanged("Message");
        }

然后在datatemplate中添加属性名称。