/// <summary> /// Shows the dialog in a seperate window displayed over the current main window. /// </summary> /// <param name="parentWindow"></param> internal void ShowDialogOutside(IMetroWindow parentWindow) { var viewModel = new MessageDialogViewModel() { Title = "Hello!", Message = "Welcome to the world of metro!" + string.Join(Environment.NewLine, "abc", "def", "ghi", "jkl", "mno", "pqr", "stu", "vwx", "yz"), DefaultResult = (int)ButtonList.NegativButtonValue, }; viewModel.SetCaption((int)ButtonList.AffirmativeButtonValue, "Hi"); viewModel.SetCaption((int)ButtonList.NegativButtonValue, "Go away!"); viewModel.SetCaption((int)ButtonList.FirstAuxilaryButtonValue, "Cancel"); var customDialog = new MWindowDialogLib.Dialogs.CustomDialog(new Demos.Views.MessageView(), viewModel); var dlg = GetService <IContentDialogService>(); var manager = dlg.Manager; var result = manager.ShowModalDialogExternal(parentWindow, customDialog , dlg.DialogSettings); // user pressed cancel, press ESC or closed via (x) button if (result != (int)ButtonList.FirstAuxilaryButtonValue) { var answer = string.Format("You said: " + viewModel.ConvertResultToString(result)); dlg.MsgBox.Show(parentWindow, answer, "Result"); } }
/// <summary> /// Hides a visible Metro Dialog instance. /// </summary> /// <param name="window">The window with the dialog that is visible.</param> /// <param name="dialog">The dialog instance to hide.</param> /// <param name="settings">An optional pre-defined settings instance.</param> /// <returns>A task representing the operation.</returns> /// <exception cref="InvalidOperationException"> /// The <paramref name="dialog"/> is not visible in the window. /// This happens if <see cref="ShowMetroDialogAsync"/> hasn't been called before. /// </exception> public Task HideMetroDialogAsync( IMetroWindow metroWindow , IBaseMetroDialogFrame dialog , IMetroDialogFrameSettings settings = null) { metroWindow.Dispatcher.VerifyAccess(); if (!metroWindow.MetroActiveDialogContainer.Children.Contains(dialog as UIElement) && !metroWindow.MetroInactiveDialogContainer.Children.Contains(dialog as UIElement)) { throw new InvalidOperationException("The provided dialog is not visible in the specified window."); } metroWindow.SizeChanged -= dialog.SizeChangedHandler; dialog.OnClose(); Task closingTask = (Task)metroWindow.Dispatcher.Invoke(new Func <Task>(dialog._WaitForCloseAsync)); return(closingTask.ContinueWith(a => { if (DialogClosed != null) { metroWindow.Dispatcher.BeginInvoke(new Action(() => DialogClosed(this, new DialogStateChangedEventArgs()))); } return (Task)metroWindow.Dispatcher.Invoke(new Func <Task>(() => { this.RemoveDialog(metroWindow, dialog); return this.HandleOverlayOnHide(metroWindow, settings); })); }).Unwrap()); }
/// <summary> /// Adds a Metro Dialog instance to the specified window and makes it visible asynchronously. /// If you want to wait until the user has closed the dialog, use <see cref="ShowMetroDialogAsyncAwaitable"/> /// <para>You have to close the resulting dialog yourself with <see cref="HideMetroDialogAsync"/>.</para> /// </summary> /// <param name="window">The owning window of the dialog.</param> /// <param name="dialog">The dialog instance itself.</param> /// <param name="settings">An optional pre-defined settings instance.</param> /// <returns>A task representing the operation.</returns> /// <exception cref="InvalidOperationException">The <paramref name="dialog"/> is already visible in the window.</exception> public Task ShowMetroDialogAsync( IMetroWindow metroWindow , IBaseMetroDialogFrame dialog , IMetroDialogFrameSettings settings = null) { metroWindow.Dispatcher.VerifyAccess(); if (metroWindow.MetroActiveDialogContainer.Children.Contains(dialog as UIElement) || metroWindow.MetroInactiveDialogContainer.Children.Contains(dialog as UIElement)) { throw new InvalidOperationException("The provided dialog is already visible in the specified window."); } return(this.HandleOverlayOnShow(metroWindow, settings).ContinueWith(z => { return (Task)metroWindow.Dispatcher.Invoke(new Func <Task>(() => { settings = settings ?? new MetroDialogFrameSettings(); SizeChangedEventHandler sizeHandler = this.SetupAndOpenDialog(metroWindow, dialog); dialog.SizeChangedHandler = sizeHandler; return dialog.WaitForLoadAsync().ContinueWith(x => { dialog.OnShown(); if (DialogOpened != null) { metroWindow.Dispatcher.BeginInvoke(new Action(() => DialogOpened(this, new DialogStateChangedEventArgs()))); } }); })); }).Unwrap()); }
internal async void ShowDialog(IMetroWindow parentWindow) { var viewModel = new MessageDialogViewModel() { Title = "Hello!", Message = "Welcome to the world of metro!", DefaultResult = (int)ButtonList.NegativButtonValue }; viewModel.SetCaption((int)ButtonList.AffirmativeButtonValue, "Hi"); viewModel.SetCaption((int)ButtonList.NegativButtonValue, "Go away!"); viewModel.SetCaption((int)ButtonList.FirstAuxilaryButtonValue, "Cancel"); var customDialog = new MWindowDialogLib.Dialogs.CustomDialog(new Demos.Views.MessageView(), viewModel); var dlg = GetService <IContentDialogService>(); var manager = dlg.Manager; var result = await manager.ShowMetroDialogAsync(parentWindow, customDialog); // user pressed cancel, press ESC or closed via (x) button if (result != (int)ButtonList.FirstAuxilaryButtonValue) { var answer = string.Format("You said: " + viewModel.ConvertResultToString(result)); await dlg.MsgBox.ShowAsync(parentWindow, answer, "Result"); } }
/// <summary> /// Shows the dialog in a seperate window displayed over the current main window. /// </summary> /// <param name="parentWindow"></param> internal void ShowDialogOutside(IMetroWindow parentWindow , bool isNegativeButtonVisible = true , bool isUserNameVisible = true) { var customDialog = CreateLoginDialog(isNegativeButtonVisible, isUserNameVisible); var viewModel = customDialog.DataContext as Demos.ViewModels.LoginDialogViewModel; var dlg = GetService <IContentDialogService>(); var result = dlg.Manager.ShowModalDialogExternal(parentWindow, customDialog , dlg.DialogSettings); if (result != DialogIntResults.OK) // user pressed cancel or not OK { return; } // user pressed cancel, press ESC or closed via (x) button if (result == DialogIntResults.CANCEL) { return; } dlg.MsgBox.Show(parentWindow , String.Format("Username: {0}\nPassword: {1}" , viewModel.Username , PasswordBoxTextChanged.ConvertToUnsecureString(viewModel.Password)) , "Authentication Information"); }
public virtual MetroVisualManager VisualManager(bool bSet = false, MetroVisualManager vm = null) { if (bSet) { _visualManager = vm; return(null); } else { if (_visualManager == null) { IMetroControl parentControl = Owner as IMetroControl; if (parentControl != null) { return(parentControl.VisualManager()); } IMetroWindow parentWindow = Owner as IMetroWindow; if (parentWindow != null) { return(parentWindow.VisualManager()); } throw new ArgumentException("Impissibile recuperare il MetroVisualManager"); } else { return(_visualManager); } } }
private void RemoveDialog(IMetroWindow metroWindow , IBaseMetroDialogFrame dialog) { if (metroWindow.MetroActiveDialogContainer.Children.Contains(dialog as UIElement)) { // remove the dialog from the container metroWindow.MetroActiveDialogContainer.Children.Remove(dialog as UIElement); // if there's an inactive dialog, bring it to the front var dlg = metroWindow.MetroInactiveDialogContainer.Children.Cast <UIElement>().LastOrDefault(); if (dlg != null) { metroWindow.MetroInactiveDialogContainer.Children.Remove(dlg); metroWindow.MetroActiveDialogContainer.Children.Add(dlg); } } else { metroWindow.MetroInactiveDialogContainer.Children.Remove(dialog as UIElement); } if (metroWindow.MetroActiveDialogContainer.Children.Count == 0) { metroWindow.RestoreFocus(); } }
/// <summary> /// Attempts to attach a given dialog window to a given /// owner main window and returns the dialog window instance. /// </summary> /// <param name="metroWindow"></param> /// <param name="dialogWindow"></param> /// <returns></returns> private Window CreateModalExternalWindow( IMetroWindow metroWindow , Window dialogWindow) { if (metroWindow == null) { return(dialogWindow); } if (dialogWindow != null && metroWindow != null && dialogWindow != metroWindow) { dialogWindow.Owner = metroWindow as Window; } // It is not necessary here because the owner is set above dialogWindow.Topmost = false; // WindowStartupLocation should be CenterOwner dialogWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner; // Set Width and Height maximum according to Owner window dialogWindow.Width = metroWindow.ActualWidth; dialogWindow.MaxHeight = metroWindow.ActualHeight; dialogWindow.SizeToContent = SizeToContent.Height; return(dialogWindow); }
/// <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); }
/// <summary> /// Shows the dialog in a seperate window displayed over the current main window. /// </summary> /// <param name="parentWindow"></param> internal void ShowDialogOutside(IMetroWindow parentWindow) { var viewModel = new Demos.ViewModels.InputDialogViewModel() { Title = "Hello!" , Message = "What is your name?" , AffirmativeButtonText = "OK" , NegativeButtonText = "Cancel" , DefaultResult = DialogIntResults.OK // Return Key => OK Clicked }; var customDialog = new MWindowDialogLib.Dialogs.CustomDialog(new Demos.Views.InputView(), viewModel); var dlg = GetService <IContentDialogService>(); var result = dlg.Manager.ShowModalDialogExternal(parentWindow, customDialog , dlg.DialogSettings); if (result != 2) // user pressed cancel or not OK { return; } // user pressed cancel, press ESC or closed via (x) button if (result == DialogIntResults.CANCEL) { return; } var message = string.Format("Hello " + viewModel.Input + "! (result: {0})", result); dlg.MsgBox.Show(parentWindow, message, "Hello"); }
/// <summary> /// Initializes a new DialogFrame object. /// </summary> /// <param name="owningWindow">The window that is the parent of the dialog.</param> /// <param name="settings">The settings for the message dialog.</param> protected DialogFrame(IMetroWindow owningWindow , IMetroDialogFrameSettings settings) : this() { DialogSettings = settings ?? new MetroDialogFrameSettings(); OwningWindow = owningWindow; }
/// <summary> /// Class constructor from parameters. /// </summary> /// <param name="parentWindow"></param> public CustomDialog(IMetroWindow parentWindow) : this(parentWindow, null) { InitializeComponent(); this.DialogThumb = null; this.Loaded += MsgBoxDialog_Loaded; }
/// <summary> /// Class constructor from parameters. /// </summary> /// <param name="parentWindow"></param> /// <param name="settings"></param> public CustomDialog(IMetroWindow parentWindow , IMetroDialogFrameSettings settings) : base(parentWindow, settings) { InitializeComponent(); this.DialogThumb = null; this.Loaded += MsgBoxDialog_Loaded; }
/// <summary> /// Method executes when Close (x) window or demo button is clicked /// /// 1> This invokes the bound ICommand CloseCommand which in turn /// 2> will invoke the event that is bound to this method... /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void CloseCustomDialog(object sender, DialogStateChangedEventArgs e) { var dlg = GetService <IContentDialogService>(); var manager = dlg.Manager; await manager.HideMetroDialogAsync(_parentWindow, _dialog); _dialog = null; _parentWindow = null; }
/// <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); }
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); }
/// <summary> /// Creates a modal dialog outside of the current main window. /// </summary> /// <param name="metroWindow">The MetroWindow</param> /// <param name="dlgControl">The outside modal window to be owned by a given <seealso cref="IMetroWindow"/></param> /// <param name="settings">Optional settings that override the global metro dialog settings.</param> /// <returns>The result that was entered or 0 if the user escape keyed the dialog...</returns> public int ShowModalDialogExternal( IMetroWindow metroWindow , IMsgBoxDialogFrame <int> dlgControl , IMetroDialogFrameSettings settings = null) { settings = settings ?? new MetroDialogFrameSettings(); // Create the outter dialog window that hosts the dialog control var dlgWindow = _metroWindowService.CreateExternalWindow(); // The window is visible on top of the mainWindow dlgWindow = CreateModalExternalWindow(metroWindow, dlgWindow); // Release the dialog opened event if there are any subscribers if (this.DialogOpened != null) { metroWindow.Dispatcher.BeginInvoke(new Action(() => DialogOpened(this, new DialogStateChangedEventArgs()))); } if (settings.MsgBoxMode == StaticMsgBoxModes.ExternalMoveable) { // Relay drag event from thumb to outer window to let user drag the dialog if (dlgControl.DialogThumb != null && dlgWindow is IMetroWindow) { ((IMetroWindow)dlgWindow).SetWindowEvents(dlgControl.DialogThumb); } } dlgWindow.Content = dlgControl; int result = 0; dlgControl.WaitForButtonPressAsync().ContinueWith(task => { result = task.Result; dlgWindow.Invoke(dlgWindow.Close); }); HandleOverlayOnShow(metroWindow, settings); dlgWindow.ShowDialog(); // Release the dialog closed event if there are any subscribers if (this.DialogClosed != null) { metroWindow.Dispatcher.BeginInvoke(new Action(() => DialogClosed(this, new DialogStateChangedEventArgs()))); } HandleOverlayOnHide(metroWindow, settings); return(result); }
/// <summary> /// Creates a MsgBoxDialog inside of the current window. /// </summary> /// <param name="window">The MetroWindow</param> /// <param name="title">The title of the MessageDialog.</param> /// <param name="message">The message contained within the MessageDialog.</param> /// <param name="style">The type of buttons to use.</param> /// <param name="settings">Optional settings that override the global metro dialog settings.</param> /// <returns>A task promising the result of which button was pressed.</returns> public Task <MsgBoxResult> ShowMsgBoxAsync( IMetroWindow metroWindow , IMsgBoxDialogFrame <MsgBoxResult> dialog , IMetroDialogFrameSettings settings = null) { metroWindow.Dispatcher.VerifyAccess(); return(this.HandleOverlayOnShow(metroWindow, settings).ContinueWith(z => { return (Task <MsgBoxResult>)metroWindow.Dispatcher.Invoke(new Func <Task <MsgBoxResult> >(() => { settings = settings ?? new MetroDialogFrameSettings(); SizeChangedEventHandler sizeHandler = this.SetupAndOpenDialog(metroWindow, dialog); dialog.SizeChangedHandler = sizeHandler; // Call this method in the dialog to wait until the dialog is closing ... return dialog.WaitForLoadAsync().ContinueWith(x => { if (DialogOpened != null) { metroWindow.Dispatcher.BeginInvoke(new Action(() => DialogOpened(this, new DialogStateChangedEventArgs()))); } return dialog.WaitForButtonPressAsync().ContinueWith(y => { //once a button as been clicked, begin removing the dialog. dialog.OnClose(); if (DialogClosed != null) { metroWindow.Dispatcher.BeginInvoke(new Action(() => DialogClosed(this, new DialogStateChangedEventArgs()))); } Task closingTask = (Task)metroWindow.Dispatcher.Invoke(new Func <Task>(() => dialog._WaitForCloseAsync())); return closingTask.ContinueWith(a => { return ((Task)metroWindow.Dispatcher.Invoke(new Func <Task>(() => { metroWindow.SizeChanged -= sizeHandler; this.RemoveDialog(metroWindow, dialog); return this.HandleOverlayOnHide(metroWindow, settings); }))).ContinueWith(y3 => y).Unwrap(); }); }).Unwrap(); }).Unwrap().Unwrap(); })); }).Unwrap()); }
private Task HandleOverlayOnShow(IMetroWindow metroWindow , IMetroDialogFrameSettings settings) { if (!metroWindow.MetroActiveDialogContainer.Children.OfType <IBaseMetroDialogFrame>().Any()) { return(settings == null || settings.AnimateShow ? metroWindow.ShowOverlayAsync() : Task.Factory.StartNew(() => metroWindow.Dispatcher.Invoke(new Action(metroWindow.ShowOverlay)))); } else { var tcs = new System.Threading.Tasks.TaskCompletionSource <object>(); tcs.SetResult(null); return(tcs.Task); } }
/// <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 , object contentDlgVM ) { var dlg = ServiceLocator.ServiceContainer.Instance.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 = new FBContentView(); //Application.Current.Resources["CustomCloseDialogTest"]; var customDialogView = new MWindowDialogLib.Dialogs.CustomDialog( parentWindow , dlgContent , contentDlgVM); _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(); }
/// <summary> /// Constructor from custom view and optional viewmodel. /// </summary> /// <param name="parentWindow"></param> /// <param name="contentView"></param> /// <param name="viewModel"></param> /// <param name="settings"></param> public CustomDialog(IMetroWindow parentWindow , object contentView , object viewModel = null , IMetroDialogFrameSettings settings = null) : base(parentWindow, settings) { InitializeComponent(); // Set the display view here ... this.PART_Msg_Content.ChromeContent = contentView; this.DialogThumb = this.PART_Msg_Content.PART_DialogTitleThumb; // Get a view and bind datacontext to it this.DataContext = viewModel; this.Loaded += MsgBoxDialog_Loaded; }
/// <summary> /// Creates a InputDialog outside of the current window. /// </summary> /// <param name="window">The MetroWindow</param> /// <param name="title">The title of the MessageDialog.</param> /// <param name="message">The message contained within the MessageDialog.</param> /// <param name="settings">Optional settings that override the global metro dialog settings.</param> /// <returns>The text that was entered or null (Nothing in Visual Basic) if the user cancelled the operation.</returns> //// public string ShowModalInputExternal( //// IMetroWindow metroWindow //// , string title //// , string message //// , Window win //// , IMetroDialogFrameSettings settings = null) //// { //// win = CreateModalExternalWindow(metroWindow, win); //// //// settings = settings ?? new MetroDialogFrameSettings(); //// //// //create the dialog control //// var dialog = new InputDialog(metroWindow, settings) //// { //// Message = message, //// Title = title, //// Input = settings.DefaultText //// }; //// //// ////SetDialogFontSizes(settings, dialog); //// //// win.Content = dialog; //// //// string result = null; //// dialog.WaitForButtonPressAsync().ContinueWith(task => //// { //// result = task.Result; //// win.Invoke(win.Close); //// }); //// //// HandleOverlayOnShow(metroWindow, settings); //// win.ShowDialog(); //// HandleOverlayOnHide(metroWindow, settings); //// return result; //// } /// <summary> /// Creates a MessageDialog ouside of the current window. /// </summary> /// <param name="window">The MetroWindow</param> /// <param name="title">The title of the MessageDialog.</param> /// <param name="message">The message contained within the MessageDialog.</param> /// <param name="style">The type of buttons to use.</param> /// <param name="settings">Optional settings that override the global metro dialog settings.</param> /// <returns>A task promising the result of which button was pressed.</returns> //// public MessageDialogResult ShowModalMessageExternal( //// IMetroWindow metroWindow //// , string title //// , string message //// , Window dialogWindow //// , MessageDialogStyle style = MessageDialogStyle.Affirmative //// , IMetroDialogFrameSettings settings = null) //// { //// dialogWindow = CreateModalExternalWindow(metroWindow, dialogWindow); //// //// settings = settings ?? new MetroDialogFrameSettings(); //// //// //create the dialog control //// var dialog = new MessageDialog(metroWindow, settings) //// { //// Message = message, //// Title = title, //// ButtonStyle = style //// }; //// //// ////SetDialogFontSizes(settings, dialog); //// //// dialogWindow.Content = dialog; //// //// MessageDialogResult result = MessageDialogResult.Affirmative; //// dialog.WaitForButtonPressAsync().ContinueWith(task => //// { //// result = task.Result; //// dialogWindow.Invoke(dialogWindow.Close); //// }); //// //// HandleOverlayOnShow(metroWindow, settings); //// dialogWindow.ShowDialog(); //// HandleOverlayOnHide(metroWindow, settings); //// return result; //// } /// <summary> /// Creates a LoginDialog outside of the current window. /// </summary> /// <param name="metroWindow">The window that is the parent of the dialog.</param> /// <param name="title">The title of the LoginDialog.</param> /// <param name="message">The message contained within the LoginDialog.</param> /// <param name="dialogWindow"></param> /// <param name="settings">Optional settings that override the global metro dialog settings.</param> /// <returns>The text that was entered or null (Nothing in Visual Basic) if the user cancelled the operation.</returns> //// public ILoginDialogData ShowModalLoginExternal( //// IMetroWindow metroWindow //// , string title //// , string message //// , Window dialogWindow //// , ILoginDialogSettings settings = null) //// { //// dialogWindow = CreateModalExternalWindow(metroWindow, dialogWindow); //// //// settings = settings ?? new LoginDialogSettings(); //// //// //create the dialog control //// LoginDialog dialog = new LoginDialog(metroWindow, settings) //// { //// Title = title, //// Message = message //// }; //// //// ////SetDialogFontSizes(settings, dialog); //// //// dialogWindow.Content = dialog; //// //// ILoginDialogData result = null; //// dialog.WaitForButtonPressAsync().ContinueWith(task => //// { //// result = task.Result; //// dialogWindow.Invoke(dialogWindow.Close); //// }); //// //// HandleOverlayOnShow(metroWindow, settings); //// dialogWindow.ShowDialog(); //// HandleOverlayOnHide(metroWindow, settings); //// //// return result; //// } #endregion Modal External dialog private void AddDialog(IMetroWindow metroWindow , IBaseMetroDialogFrame dialog) { metroWindow.StoreFocus(); // if there's already an active dialog, move to the background var activeDialog = metroWindow.MetroActiveDialogContainer.Children.Cast <UIElement>().SingleOrDefault(); if (activeDialog != null) { metroWindow.MetroActiveDialogContainer.Children.Remove(activeDialog); metroWindow.MetroInactiveDialogContainer.Children.Add(activeDialog); } // add the dialog to the container} metroWindow.MetroActiveDialogContainer.Children.Add(dialog as UIElement); }
internal async void ShowDialog(IMetroWindow parentWindow , bool isNegativeButtonVisible = true , bool isUserNameVisible = true) { var customDialog = CreateLoginDialog(isNegativeButtonVisible, isUserNameVisible); var viewModel = customDialog.DataContext as Demos.ViewModels.LoginDialogViewModel; var dlg = GetService <IContentDialogService>(); var manager = dlg.Manager; var result = await manager.ShowMetroDialogAsync(parentWindow, customDialog); if (result == DialogIntResults.OK) { var msgResult = await dlg.MsgBox.ShowAsync(parentWindow , String.Format("Username: {0}\nPassword: {1}", viewModel.Username, PasswordBoxTextChanged.ConvertToUnsecureString(viewModel.Password)) , "Authentication Information"); } }
/// <summary> /// Creates an External MsgBox dialog outside of the main window. /// </summary> /// <param name="metroWindow"></param> /// <param name="dlgControl"></param> /// <param name="settings"></param> /// <returns></returns> public MsgBoxResult ShowModalDialogExternal( IMetroWindow metroWindow , IMsgBoxDialogFrame <MsgBoxResult> dlgControl , IMetroDialogFrameSettings settings = null) { settings = settings ?? new MetroDialogFrameSettings(); // Create the outter dialog window that hosts the dialog control var dlgWindow = _metroWindowService.CreateExternalWindow(); // The window is visible on top of the mainWindow dlgWindow = CreateModalExternalWindow(metroWindow, dlgWindow); if (settings.MsgBoxMode == StaticMsgBoxModes.ExternalMoveable) { // Relay drag event from thumb to outer window to let user drag the dialog if (dlgControl.DialogThumb != null && dlgWindow is IMetroWindow) { ((IMetroWindow)dlgWindow).SetWindowEvents(dlgControl.DialogThumb); } } dlgWindow.Content = dlgControl; MsgBoxResult result = MsgBoxResult.None; dlgControl.WaitForButtonPressAsync().ContinueWith(task => { result = task.Result; dlgWindow.Invoke(dlgWindow.Close); }); HandleOverlayOnShow(metroWindow, settings); dlgWindow.ShowDialog(); HandleOverlayOnHide(metroWindow, settings); return(result); }
private SizeChangedEventHandler SetupAndOpenDialog( IMetroWindow metroWindow , IBaseMetroDialogFrame dialog) { dialog.SetZIndex((int)metroWindow.OverlayBox.GetValue(Panel.ZIndexProperty) + 1); dialog.MinHeight = metroWindow.ActualHeight / 4.0; dialog.MaxHeight = metroWindow.ActualHeight; SizeChangedEventHandler sizeHandler = (sender, args) => { dialog.MinHeight = metroWindow.ActualHeight / 4.0; dialog.MaxHeight = metroWindow.ActualHeight; }; metroWindow.SizeChanged += sizeHandler; this.AddDialog(metroWindow, dialog); dialog.OnShown(); return(sizeHandler); }