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 HandleSimulatorCanceled()
        {
            simulator = null;
            btnStart.IsEnabled = true;
            btnStop.IsEnabled = false;
            btnLoad.IsEnabled = true;
            if (quickActionButtons != null)
                foreach (var bt in quickActionButtons)
                    bt.IsEnabled = true;

            if (currentQuickAction != null)
            {
                currentQuickAction = null;
                RefreshProjectControls();
            }

            if (closeWindowAfterStop)
                Close();
        }