//The State should be called before any await key word to avoid the system.InvalidOperationException: You can only use State between OnNavigatedTo and OnNavigatedFrom Exception //http://blog.ariankulp.com/2014/04/you-can-only-use-state-between.html protected override async void OnNavigatedTo(NavigationEventArgs e) { progressIndicator = RetrieveProgressIndicator(); loadingPanel = RetrieveLoadingContainer(); if (isManagingProgressIndicatorItself == false) { progressIndicator.IsVisible = true; if(loadingPanel != null && displayLoaderPanelNextTime == true) { loadingPanel.Visibility = Visibility.Visible; } } SendPage(); mainContener = RetrieveMainContainer(); connectivityContainer = RetrieveConnectivityContainer(); LoadQueryString(); try { if (viewModel == null && isMVVMUsed == true) { if (State.ContainsKey(M4MPhoneApplicationPage.VIEW_MODEL_KEY) == true) { viewModel = State[M4MPhoneApplicationPage.VIEW_MODEL_KEY] as M4MBaseViewModel; } else { viewModel = await ComputeViewModel(); } } } catch (M4MConnectivityException exception) { OnDisplayConnectivityLayout(); throw new M4MConnectivityException(exception); } OnFullfillDisplayObjects(); if (connectivityContainer != null) { connectivityContainer.Visibility = Visibility.Collapsed; } if (mainContener != null) { mainContener.Visibility = Visibility.Visible; } if (isManagingProgressIndicatorItself == false) { progressIndicator.IsVisible = false; if(loadingPanel != null) { loadingPanel.Visibility = Visibility.Collapsed; } } base.OnNavigatedTo(e); }
/// <summary> /// Invokes this method when you want to reload the business objects, from memory, local persistence, via web services, necessary for the entity processing. /// </summary> /// <returns></returns> protected async Task Refresh() { if (isManagingProgressIndicatorItself == false) { progressIndicator.IsVisible = true; if(loadingPanel != null && displayLoaderPanelNextTime == true) { if (connectivityContainer != null) { connectivityContainer.Visibility = Visibility.Collapsed; } mainContener.Visibility = Visibility.Collapsed; loadingPanel.Visibility = Visibility.Visible; } } if (viewModel == null) { try { viewModel = await ComputeViewModel(); } catch (M4MConnectivityException exception) { OnDisplayConnectivityLayout(); throw new M4MConnectivityException(exception); } OnFullfillDisplayObjects(); if (connectivityContainer != null) { connectivityContainer.Visibility = Visibility.Collapsed; } if (isManagingProgressIndicatorItself == false) { progressIndicator.IsVisible = false; if(loadingPanel != null) { loadingPanel.Visibility = Visibility.Collapsed; } } if (mainContener != null) { mainContener.Visibility = Visibility.Visible; } } else { try { await RefreshViewModel(); } catch (M4MConnectivityException exception) { if (isManagingProgressIndicatorItself == false) { progressIndicator.IsVisible = false; if(displayLoaderPanelNextTime == true) { OnDisplayConnectivityLayout(); } } throw new M4MConnectivityException(exception); } } if (isManagingProgressIndicatorItself == false) { progressIndicator.IsVisible = false; if (loadingPanel != null) { loadingPanel.Visibility = Visibility.Collapsed; } } if (mainContener != null) { mainContener.Visibility = Visibility.Visible; } }