/// <summary> /// 异步获取实例 /// </summary> /// <returns></returns> public static async Task <MemoryListViewModel> GetInstanceAsync() { if (_uniqueInstance != null) { return(_uniqueInstance); } lock (Locker) { // 如果类的实例不存在则创建,否则直接返回 if (_uniqueInstance == null) { // ReSharper disable once PossibleMultipleWriteAccessInDoubleCheckLocking _uniqueInstance = new MemoryListViewModel(); } } _uniqueInstance._memoryList = await MemoryList.GetInstanceAsync(); foreach (var memoryModel in _uniqueInstance._memoryList.MemoryModels) { var memoryViewModel = await MemoryViewModel.GetInstanceAsync(memoryModel); _uniqueInstance.MemoryViewModels.Add(memoryViewModel); } return(_uniqueInstance); }
/// <summary> /// 异步获取实例 /// </summary> /// <returns></returns> public static async Task <MemoryViewModel> GetInstanceAsync(MemoryModel memoryModel = null) { var memoryViewModel = new MemoryViewModel(memoryModel) { _imageViewModels = new List <ImageViewModel>() }; if (memoryModel?.ImageModels == null) { return(memoryViewModel); } foreach (var imageModel in memoryModel.ImageModels) { var imageViewModel = await ImageViewModel.GetInstanceAsync(imageModel); memoryViewModel._imageViewModels.Add(imageViewModel); } if (memoryViewModel._imageViewModels != null && memoryViewModel._imageViewModels.Count > 0) { memoryViewModel.CoverImage = memoryViewModel._imageViewModels[0].ThumbnailImage; } else { memoryViewModel.CoverImage = new BitmapImage(new Uri("ms-appx:///Assets/Gray.png")); } return(memoryViewModel); }
/// <summary> /// 删除一个回忆 /// </summary> public void Delete(MemoryViewModel memoryViewModel) { if (!MemoryViewModels.Contains(memoryViewModel)) { return; } _memoryList.Delete(memoryViewModel); MemoryViewModels.Remove(memoryViewModel); }
/// <summary> /// 增加一条回忆 /// </summary> public void Add(MemoryViewModel memoryViewModel) { if (MemoryViewModels.Contains(memoryViewModel)) { return; } _memoryList.Add(memoryViewModel); MemoryViewModels.Add(memoryViewModel); }