コード例 #1
0
ファイル: ProgressDialogDemos.cs プロジェクト: RyanFu/MLib
        /// <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
ファイル: ProgressDialogDemos.cs プロジェクト: RyanFu/MLib
        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
ファイル: ProgressDialogDemos.cs プロジェクト: RyanFu/MLib
        /// <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);
            }
            );
        }
コード例 #4
0
ファイル: ProgressDialogDemos.cs プロジェクト: RyanFu/MLib
 /// <summary>
 /// Creates a <seealso cref="MWindowDialogLib.Dialogs.CustomDialog"/> that contains a <seealso cref="ProgressView"/>
 /// in its content and has a <seealso cref="ProgressViewModel"/> attached to its datacontext,
 /// </summary>
 /// <param name="viewModel"></param>
 /// <returns></returns>
 private CustomDialog CreateProgressDialog(Demos.ViewModels.ProgressDialogViewModel viewModel)
 {
     return(new MWindowDialogLib.Dialogs.CustomDialog(new Demos.Views.ProgressView(), viewModel));
 }