示例#1
0
        /// <summary>
        /// Method demos different sample methods for displaying a progress
        /// dialog with progress that cannot be cancelled because:
        ///
        /// - UI shows no Cancel button
        /// - Backend process does not evaluate <seealso cref="CancellationToken"/> parameter
        /// </summary>
        /// <param name="parentWindow"></param>
        /// <param name="progressIsFinite"></param>
        /// <param name="closeDialogOnProgressFinished"></param>
        /// <param name="isCancelable"></param>
        /// <returns></returns>
        internal async Task <int> ShowNoCancelProgressAsync(
            IMetroWindow parentWindow
            , bool progressIsFinite
            , bool closeDialogOnProgressFinished = false
            , bool isCancelable = true
            )
        {
            bool   isVisible    = true;
            string progressText = null;

            var progressColl = new ProgressSettings[1];

            // Configure a progress display with its basic settings
            progressColl[0] = new ProgressSettings(0, 1, 0, progressIsFinite
                                                   , progressText, isCancelable, isVisible
                                                   , closeDialogOnProgressFinished)
            {
                Title      = "Please wait...",
                Message    = "We are baking some cupcakes!",
                ExecAction = GenSampleNonCancelableProocess()
            };

            var viewModel    = new Demos.ViewModels.ProgressDialogViewModel();
            var customDialog = CreateProgressDialog(viewModel);

            var dlg     = GetService <IContentDialogService>();
            var manager = dlg.Manager;

            EventHandler <DialogStateChangedEventArgs> OnViewOpenedEvent = (s, e) =>
            {
                // Start Task in ProgressViewModel and wait for result in Dialog below
                // But do not start before view is visible because task could otherwise
                // finish before view close request can be handled by the view ...
                viewModel.StartProcess(progressColl);
            };

            manager.DialogOpened += OnViewOpenedEvent;

            int result = -1;

            try
            {
                result = await manager.ShowMetroDialogAsync(parentWindow, customDialog);
            }
            finally
            {
                manager.DialogOpened -= OnViewOpenedEvent;
            }

            Console.WriteLine("Process Result: '{0}'", viewModel.Progress.ProcessResult);

            return(result);
        }
示例#2
0
        internal void ShowDialogOutside(IMetroWindow parentWindow
                                        , bool progressIsFinite
                                        , bool closeDialogOnProgressFinished = false
                                        , bool isCancelable = true
                                        )
        {
            bool   isVisible    = true;
            string progressText = null;

            var progressColl = new ProgressSettings[1];

            // Configure a progress display with its basic settings
            progressColl[0] = new ProgressSettings(0, 1, 0, progressIsFinite
                                                   , progressText, isCancelable, isVisible
                                                   , closeDialogOnProgressFinished)
            {
                Title      = "Progress Outside",
                Message    = "This progress is shown in a seperate window above the main window",
                ExecAction = GenCancelableSampleProcess()
            };

            var viewModel    = new Demos.ViewModels.ProgressDialogViewModel();
            var customDialog = CreateProgressDialog(viewModel);

            var dlg     = GetService <IContentDialogService>();
            var manager = GetService <IContentDialogService>().Manager;

            EventHandler <DialogStateChangedEventArgs> OnViewOpenedEvent = (s, e) =>
            {
                // Start Task in ProgressViewModel and wait for result in Dialog below
                // But do not start before view is visible because task could otherwise
                // finish before view close request can be handled by the view ...
                viewModel.StartProcess(progressColl);
            };

            manager.DialogOpened += OnViewOpenedEvent;

            int result = -1;

            try
            {
                result = dlg.Manager.ShowModalDialogExternal(parentWindow, customDialog
                                                             , dlg.DialogSettings);
            }
            finally
            {
                manager.DialogOpened -= OnViewOpenedEvent;
            }

            Console.WriteLine("Process Result: '{0}'", viewModel.Progress.ProcessResult);
        }
示例#3
0
        /// <summary>
        /// Shows a sample progress dialog that was invoked via a bound viewmodel.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="progressIsFinite"></param>
        /// <param name="closeDialogOnProgressFinished"></param>
        /// <param name="isCancelable"></param>
        internal async void ShowDialogFromVM(
            object context
            , bool progressIsFinite
            , bool closeDialogOnProgressFinished = false
            , bool isCancelable = true
            )
        {
            bool   isVisible    = true;
            string progressText = null;

            var progressColl = new ProgressSettings[1];

            // Configure a progress display with its basic settings
            progressColl[0] = new ProgressSettings(0, 1, 0, progressIsFinite
                                                   , progressText, isCancelable, isVisible
                                                   , closeDialogOnProgressFinished)
            {
                Title      = "Progress from VM",
                Message    = "Progressing all the things, wait a few seconds",
                ExecAction = GenCancelableSampleProcess()
            };

            var viewModel    = new Demos.ViewModels.ProgressDialogViewModel();
            var customDialog = CreateProgressDialog(viewModel);

            var coord   = GetService <IContentDialogService>().Coordinator;
            var manager = GetService <IContentDialogService>().Manager;

            EventHandler <DialogStateChangedEventArgs> OnViewOpenedEvent = (s, e) =>
            {
                // Start Task in ProgressViewModel and wait for result in Dialog below
                // But do not start before view is visible because task could otherwise
                // finish before view close request can be handled by the view ...
                viewModel.StartProcess(progressColl);
            };

            manager.DialogOpened += OnViewOpenedEvent;

            await coord.ShowMetroDialogAsync(context, customDialog).ContinueWith
            (
                t =>
            {
                manager.DialogOpened -= OnViewOpenedEvent;
                Console.WriteLine(t.Result);
            }
            );
        }