示例#1
0
        private async void AddParticles_Click(object sender, RoutedEventArgs e)
        {
            MainWindow Window = (MainWindow)Application.Current.MainWindow;
            Species    S      = Species;

            CustomDialog NewDialog = new CustomDialog();

            NewDialog.HorizontalContentAlignment = HorizontalAlignment.Center;

            DialogSpeciesParticleSets NewDialogContent = new DialogSpeciesParticleSets(Window.ActivePopulation, S);

            NewDialogContent.Close += async() => await Window.HideMetroDialogAsync(NewDialog);

            NewDialogContent.Add += async() =>
            {
                await Window.HideMetroDialogAsync(NewDialog);

                var NewSpeciesProgress = await Window.ShowProgressAsync("Please wait while particle statistics are updated...",
                                                                        "");

                NewSpeciesProgress.SetIndeterminate();

                await Task.Run(() =>
                {
                    S.AddParticles(NewDialogContent.ParticlesFinal);

                    S.CalculateParticleStats();

                    S.Commit();
                    S.Save();
                });

                await NewSpeciesProgress.CloseAsync();
            };

            NewDialog.Content = NewDialogContent;
            await Window.ShowMetroDialogAsync(NewDialog);
        }