private void OnPatientSelected(Object patient) { CurrentPatinent = (LocalPatient)patient;//LocalCache.Instance.PatientsRepository.Patients.FirstOrDefault(item => item.Id == patientId); PatientId = CurrentPatinent.Id; PatientInformationViewModel = CurrentPatinent.ToPatientInformationViewModel(this); InterventionsVisibility = Visibility.Visible; MetroLoadingViewModel = new MetroLoadingViewModel(true); //MetroLoadingViewModel.MetroLoadingViewReference = new MetroLoadingView(); // get the Ui thread context TaskScheduler _uiScheduler = TaskScheduler.FromCurrentSynchronizationContext(); Action DoInBackground = new Action(() => { GetInterventions(); }); Action DoOnUiThread = new Action(() => { UpdateInterventionsCollection(); }); // start the background task backgroundTask = Task.Factory.StartNew(() => DoInBackground()); // when t1 is done run t1..on the Ui thread. uiTask = backgroundTask.ContinueWith(t => DoOnUiThread(), _uiScheduler); // Interventions = new ObservableCollection<InterventionDetails>( DatabaseHandler.Instance.GetPatientInterventions(PatientId).Select(item => item.ToInterventionDetails())); }
private void ConnectToServerAndLogin(string loggedUser) { IsLoginVisible = Visibility.Collapsed; IsContentVisible = Visibility.Visible; UserName = loggedUser; MetroLoadingViewModel = new MetroLoadingViewModel(true); MetroLoadingViewModel.UserName = UserName; AnimateWhenLoading(); }