public override async void OnNavigatedTo(NavigationParameters parameters) { IsBusy = true; switch (parameters.GetNavigationMode()) { case NavigationMode.Back: TodoItems.ReplaceRange(await _dataContext.TodoItems.ReadAllItemsAsync()); break; case NavigationMode.New: //await _cloudService.LoginAsync(); TodoItems.AddRange(await _dataContext.TodoItems.ReadAllItemsAsync()); break; } IsBusy = false; }
public TodoItemsListVm(ITodoItemsService todoItemsService) { this.todoItemsService = todoItemsService; // Firstly get all items, and after that watch to changes. todoItemsService.GetAll() .Select(items => items.Select(todoItem => new TodoItemVm(todoItem))) .Do(items => TodoItems.AddRange(items)) .SelectMany(_ => todoItemsService.TodoItemAdded) .Subscribe(todoItem => TodoItems.Add(new TodoItemVm(todoItem))); this.WhenAnyValue(x => x.SelectedTodoItem) .Where(todoItem => todoItem != null) .Select(todoItem => todoItem.Model) .SelectMany(todoItem => todoItemsService.SetCurrentTodoItem(todoItem)) .Subscribe(); }
public override void OnNavigatedTo(NavigationParameters parameters) { IsBusy = true; switch (parameters.GetNavigationMode()) { case NavigationMode.Back: if (parameters.ContainsKey("todoItem")) { TodoItems.Add(parameters.GetValue <TodoItem>("todoItem")); } break; case NavigationMode.New: TodoItems.AddRange(parameters.GetValues <string>("todo") .Select(n => new TodoItem { Name = n })); break; } IsBusy = false; }
public override void OnNavigatedTo(NavigationParameters parameters) #endif { IsBusy = true; switch (parameters.GetNavigationMode()) { case NavigationMode.Back: #if (UseAzureMobileClient) #if (UseMvvmHelpers) TodoItems.ReplaceRange(await _dataContext.TodoItems.ReadAllItemsAsync()); #else Todoitems.Clear(); foreach (var item in await _dataContext.TodoItems.ReadAllItemsAsync()) { TodoItems.Add(item); } #endif #elseif (UseRealm) // Do anything you want to do only when Navigating Back to the View #else if (parameters.ContainsKey("todoItem")) { TodoItems.Add(parameters.GetValue <TodoItem>("todoItem")); } #endif break; case NavigationMode.New: #if (UseAzureMobileClient) #if (UsesAuthentication) await _cloudService.LoginAsync(); #endif #if (UseMvvmHelpers) TodoItems.AddRange(await _dataContext.TodoItems.ReadAllItemsAsync()); #else foreach (var item in await _dataContext.TodoItems.ReadAllItemsAsync()) { TodoItems.Add(item); } #endif #elseif (UseRealm) TodoItems = _realm.All <TodoItem>(); #else #if (UseMvvmHelpers) TodoItems.AddRange(parameters.GetValues <string>("todo") .Select(n => new TodoItem { Name = n })); #else foreach (var item in parameters.GetValues <string>("todo")) { TodoItems.Add(new TodoItem() { Name = item }); } #endif #endif break; } IsBusy = false; }