コード例 #1
0
ファイル: CustomDialogDemos.cs プロジェクト: RyanFu/MLib
        /// <summary>
        /// This method demos a custom dialog that requires no buttons
        /// but will be closed after an ellapsed interval of time.
        /// </summary>
        /// <param name="parentWindow"></param>
        internal async void ShowCustomDialog(IMetroWindow parentWindow)
        {
            var dlg     = GetService <IContentDialogService>();
            var manager = dlg.Manager;

            object dlgContent = Application.Current.Resources["CustomDialogTest"];

            var viewModel = new Demos.ViewModels.MsgDemoViewModel()
            {
                DialogCanCloseViaChrome       = false
                , CloseWindowButtonVisibility = false
                , Title = "Custom Dialog"
            };

            var customDialogView = new MWindowDialogLib.Dialogs.CustomDialog(
                parentWindow
                , dlgContent
                , viewModel);

            #pragma warning disable CS4014
            // Dialog is not awaited to allow next message box to be displayed on top of it.
            manager.ShowMetroDialogAsync(parentWindow, customDialogView);
            #pragma warning restore CS4014

            viewModel.Message = "A message box will appear in 5 seconds.";

            await Delay(5000);

            await dlg.MsgBox.ShowAsync(parentWindow, "This message is shown on top of another.", "Secondary dialog");

            viewModel.Message = "The dialog will close in 2 seconds.";
            await Delay(2000);

            await manager.HideMetroDialogAsync(parentWindow, customDialogView);
        }
コード例 #2
0
ファイル: CustomDialogDemos.cs プロジェクト: RyanFu/MLib
        /// <summary>
        /// This method demos a custom dialog that can envoke an external
        /// close event via the dialogs viewmodel.
        ///
        /// 1) The DialogClosed event of the viewmodel is raised via
        ///    the CloseCommand and executes the CloseCustomDialog method below.
        ///    The CloseCustomDialog method executes the manager's
        ///    HideMetroDialogAsync method which in turn raises
        ///
        /// 2) The manager's DialogClosed event which in turn
        ///
        /// 3) Shows another dialog via the inline bound event...
        /// </summary>
        /// <param name="parentWindow"></param>
        internal async void ShowAwaitCustomDialog(IMetroWindow parentWindow)
        {
            var dlg     = GetService <IContentDialogService>();
            var manager = dlg.Manager;

            EventHandler <DialogStateChangedEventArgs> dialogManagerOnDialogOpened = null;

            dialogManagerOnDialogOpened = (o, args) => {
                manager.DialogOpened -= dialogManagerOnDialogOpened;
                Console.WriteLine("Custom Dialog opened!");
            };
            manager.DialogOpened += dialogManagerOnDialogOpened;

            EventHandler <DialogStateChangedEventArgs> dialogManagerOnDialogClosed = null;

            dialogManagerOnDialogClosed = (o, args) => {
                manager.DialogClosed -= dialogManagerOnDialogClosed;
                Console.WriteLine("Custom Dialog closed!");

                dlg.MsgBox.Show(parentWindow, "Dialog gone", "The custom dialog has closed");
            };

            manager.DialogClosed += dialogManagerOnDialogClosed;

            // Construct a viewmodel with the interaction logic
            var viewModel = new Demos.ViewModels.MsgDemoViewModel();

            viewModel.DialogClosed += CloseCustomDialog;

            // Construct a view with the content to be displayed
            var dlgContent = Application.Current.Resources["CustomCloseDialogTest"];

            var customDialogView = new MWindowDialogLib.Dialogs.CustomDialog(
                parentWindow
                , dlgContent
                , viewModel);

            _dialog       = customDialogView;
            _parentWindow = parentWindow;

            await manager.ShowMetroDialogAsync(parentWindow, customDialogView);

            // Waits until the either close button is clicked to invoke the CloseCommand in the viewModel
            await _dialog.WaitUntilUnloadedAsync();
        }