gpt4 book ai didi

c# - 更新 ListView 项目值不工作 Windows Phone 8.1

转载 作者:行者123 更新时间:2023-11-30 22:01:58 25 4
gpt4 key购买 nike

当我尝试更新 ListView 中插入元素的值时,我没有在手机上看到更改,但在调试消息中我看到了更改。这是我的代码。

 private void chat_LayoutUpdated(object sender, object e)
{
foreach (Message item in chat.Items)
{
item.MessageTime = GetRelativeDate(item.MessageDateTime);
Debug.WriteLine(item.MessageTime); //Display changed value(Delta computed on step before) but on phone screen value didn't change;
}

}

GetRelativeDate//长函数,返回当前时间和消息发送时间之间的差值。

class Message // Model of chat message
{
public string MessageText { get; set; }
public string MessageTime { get; set; } // This value i want to change in ListView.
public DateTime MessageDateTime { get; set; }
}

XAML

<TextBlock Grid.Column="0"
FontSize="22"
Text="{Binding MessageText}" />
<TextBlock
Grid.Column="1"
Grid.Row="1"
FontSize="10"
Text="{Binding MessageTime}" />

P/s 也许我需要一些更具体的东西来用作聊天窗口。

无论如何,谢谢你们,我将非常感谢任何答案或建议。

最佳答案

需要实现INofityPropertyChanged

MSDN: inotifypropertychanged Example


MSDN 文章中的示例:

public class DemoCustomer : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;

// This method is called by the Set accessor of each property.
// The CallerMemberName attribute that is applied to the optional propertyName
// parameter causes the property name of the caller to be substituted as an argument.
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}

private DemoCustomer()
{
}

private string customerNameValue = String.Empty;
public string CustomerName
{
get
{
return this.customerNameValue;
}

set
{
if (value != this.customerNameValue)
{
this.customerNameValue = value;
NotifyPropertyChanged();
}
}
}
}

关于c# - 更新 ListView 项目值不工作 Windows Phone 8.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27262248/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com