private void btnLoad_Click(object sender, RoutedEventArgs e) { if (openFileDialog.ShowDialog(this) == true) { // Try to load the given project. try { using (FileStream fs = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { XmlProjectDeserializer deser = new XmlProjectDeserializer(); project = deser.Deserialize(fs); } } catch (Exception ex) { TaskDialog dialog = new TaskDialog() { Title = AppName, MainInstruction = "Could not load the selected project.", Content = ex.Message, ExpandedInformation = GetExceptionDetailsText(ex), MainIcon = TaskDialog.TaskDialogIcon.SecurityErrorBar, MainUpdateIcon = TaskDialog.TaskDialogIcon.Stop, CommonButtons = TaskDialog.TaskDialogButtons.OK }; dialog.Flags |= TaskDialog.TaskDialogFlags.SizeToContent | TaskDialog.TaskDialogFlags.ExpandFooterArea; dialog.Show(this); return; } if (quickActionButtons != null) { foreach (var b in quickActionButtons) gridProjectControls.Children.Remove(b); quickActionButtons = null; } RefreshProjectControls(); // For each quick action, create a button. quickActionButtons = new Button[project.Configuration.QuickActions.Count]; for (int idx = 0; idx < project.Configuration.QuickActions.Count; idx++) { int i = idx; var quickAction = project.Configuration.QuickActions[i]; Button b = quickActionButtons[i] = new Button(); b.Height = 21; b.HorizontalAlignment = HorizontalAlignment.Left; b.VerticalAlignment = VerticalAlignment.Top; b.Margin = new Thickness(0, 2 + 23 * i, 0, 0); b.Content = " " + quickAction.Name + " "; gridProjectControls.Children.Add(b); Grid.SetRow(b, 1); b.Click += async (_s, _e) => { currentQuickAction = quickAction; RefreshProjectControls(); await RunSimulatorAsync(); }; } } }
private void btnLoad_Click(object sender, RoutedEventArgs e) { if (openFileDialog.ShowDialog(this) == true) { // Try to load the given project. try { using (FileStream fs = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read)) { XmlProjectDeserializer deser = new XmlProjectDeserializer(); project = deser.Deserialize(fs); } } catch (Exception ex) { MessageBox.Show(this, "Could not load the given project.\r\n\r\n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } RefreshProjectControls(); } }