【问题标题】:How to update a ListViewItem in a ListView Windows Phone 8.1如何在 ListView Windows Phone 8.1 中更新 ListViewItem
【发布时间】:2016-11-21 15:11:29
【问题描述】:

我正在尝试更新 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));
    }
}

【问题讨论】:

  • 任何示例代码都将有助于找出问题所在。但是,请确保您为尝试更新的模型属性实施了正确的绑定。

标签: c# listview windows-phone-8.1


【解决方案1】:

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

这样做:

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

然后在数据模板中添加属性名称。

【讨论】:

  • 你能给我举个例子吗?我已经试过了。谢谢!
  • 如果您可以发布您的代码(模型)会更有帮助。
  • 现在看一下,我已经添加了。谢谢!
  • 现在,有没有办法让每个属性都做到这一点? (无需手动)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-20
  • 1970-01-01
相关资源
最近更新 更多