当我尝试更新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/