MAUI 更新 CollectionView 事件倒计时
您好,我正在尝试进行活动倒计时,但遇到了一些问题。
该函数被调用:
private void RunEventCountdowns()
{
Device.StartTimer(new TimeSpan(0, 0, 1), () =>
{
if (isCounting)
{
Device.BeginInvokeOnMainThread(() =>
{
OnPropertyChanged("propChanged");
});
return true;
}
else
{
return false;
}
});
}
isCounting 在 OnAppearing() 中设置为 true
然后:
public event PropertyChangedEventHandler propChanged;
private void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = propChanged;
foreach (var evt in EventList)
{
tSpan = evt.Date - DateTime.Now;
evt.Time = tSpan;
System.Diagnostics.Debug.WriteLine(evt.Name + " is this far away: " + evt.Time.ToString());
}
}
Tspan 只是一个 Timespan
前端的绑定中途有效 - name 属性看起来很好,但倒计时字符串永远不会更新。如果我将 itemsource 设置为 null,然后将其更改回我的 observablecollection 源,它会更新..但随后我的内存不断增加,并且似乎不是执行此操作的正确方法。
我的调试几乎显示了我想在前端看到的信息。 我在这里做错了什么?
Hello I am attempting to make an event countdown but running into some issues.
This function gets called:
private void RunEventCountdowns()
{
Device.StartTimer(new TimeSpan(0, 0, 1), () =>
{
if (isCounting)
{
Device.BeginInvokeOnMainThread(() =>
{
OnPropertyChanged("propChanged");
});
return true;
}
else
{
return false;
}
});
}
isCounting is set true in OnAppearing()
Then:
public event PropertyChangedEventHandler propChanged;
private void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = propChanged;
foreach (var evt in EventList)
{
tSpan = evt.Date - DateTime.Now;
evt.Time = tSpan;
System.Diagnostics.Debug.WriteLine(evt.Name + " is this far away: " + evt.Time.ToString());
}
}
Tspan is just a Timespan
The binding on front end halfway works - the name property appears fine but the countdown string never updates. If I set itemsource to null then change it back to my observablecollection source it updates..but then my memory constantly increases, and doesn't seem like the proper way to do this.
My debug pretty much shows the information I want to see on the front end.
What am I doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在第一条评论的帮助下,我能够通过在我的模型上添加带有 PropertyChanged 的设置器来解决这个问题。
以及以下事件:
With the help of the first comment I was able to figure this out by adding a setter with PropertyChanged on my model.
As well as the following event: