(1)在使用Akavache时,我在获取ObservableCollection的CollectionChanged事件时遇到了问题,以下是我的代码(简化)
GraphCollection = new ObservableCollection<UserData>();
_cache.GetOrFetchObject(TabType.Graph.ToString(),
async () => await _dataStore.GetAllDocuments(TabType.Graph))
.Subscribe(
GraphList =>
{
GraphCollection = new ObservableCollection<UserData>(GraphList);
//GraphCollection.Shuffle();
NoGraphItems = GraphCollection.Count == 0;
});
GraphCollection.CollectionChanged += (sender, args) =>
{
NoGraphItems = GraphCollection.Count == 0;
};理想情况下,当我添加/删除数据时,我希望触发事件来检查集合是否为空,然后分配一个bool属性来判断它是否为空。
我像这样做简单的添加/删除,然后调用RefreshCache方法来使数据无效并重新创建数据,不确定这是否也是最有效的方法。
var graphRecord = GraphCollection.FirstOrDefault(x => x.Id == data.Id);
GraphCollection.Remove(dreamRecord);
RefreshCache(TabType.Graphs, DreamsCollection);
private void RefreshCache(TabType tabType, ObservableCollection<UserData> collection)
{
_cache.InvalidateObject<UserData>(tabType.ToString());
_cache.InsertObject(tabType.ToString(), collection);
}(2)当前未设置DateTime偏移量,需要设置吗?有没有人能给我举个例子,说明怎么写出来,文档里没有明确说明。
DateTimeOffset? absoluteExpiration发布于 2021-09-02 01:59:49
您的订阅将创建一个新的GraphCollection实例,以便分配给原始实例的事件处理程序不再适用于新实例
试试这个吧
GraphList =>
{
GraphCollection = new ObservableCollection<UserData>(GraphList);
NoGraphItems = GraphCollection.Count == 0;
GraphCollection.CollectionChanged += // handler goes here
});https://stackoverflow.com/questions/69021122
复制相似问题