/// <summary> /// Initializes the viewModel when the view has been loaded, and prevents reinitialization /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void OnLoaded(object sender, RoutedEventArgs e) { try { if (!isLoaded) { isLoaded = true; await viewModel.InitializeAsync(); } } //Writes a message to the logger if an exception is caught while loading catch (Exception ex) { MessageBox.Show(ex.Message, "Der opstod en fejl.", MessageBoxButton.OK, MessageBoxImage.Error); await Logger.LogAsync(ex); } }
/// <summary> /// Runs when Controller is loaded /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void OnLoaded(object sender, RoutedEventArgs e) { try { // Check if isLoaded is false if (!isLoaded) { // Set isLoaded to true isLoaded = !isLoaded; await viewModel.InitializeAsync(); } } catch (Exception ex) { Logger.Log(ex); Exception originalException = ex.GetOriginalException(); MessageBox.Show(originalException.Message, "An error has occurred, please check the log file for further information.", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// Initialize the viewModel when the view has been loaded, and prevents reinitialization /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void OnLoaded(object sender, RoutedEventArgs e) { try { // Check if this has already been loaded if (!isLoaded) { // Change isLoaded value isLoaded = !isLoaded; // Initialize the viewModel await viewModel.InitializeAsync(); } } catch (Exception ex) { // Output error message MessageBox.Show(ex.Message, "Der opstod en fejl.", MessageBoxButton.OK, MessageBoxImage.Error); // Log Exception await Logger.LogAsync(ex); } }