public Task ShowMetroDialogAsync(object context, BaseMetroDialog dialog, MetroDialogSettings settings = null) { var metroWindow = GetMetroWindow(context); return(metroWindow.ShowMetroDialogAsync(dialog, settings)); }
/// <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 static Task HideMetroDialogAsync(this MetroWindow window, BaseMetroDialog dialog, MetroDialogSettings settings = null) { window.Dispatcher.VerifyAccess(); if (!window.metroActiveDialogContainer.Children.Contains(dialog) && !window.metroInactiveDialogContainer.Children.Contains(dialog)) { throw new InvalidOperationException("The provided dialog is not visible in the specified window."); } window.SizeChanged -= dialog.SizeChangedHandler; dialog.OnClose(); Task closingTask = (Task)window.Dispatcher.Invoke(new Func <Task>(dialog._WaitForCloseAsync)); return(closingTask.ContinueWith(a => { if (DialogClosed != null) { window.Dispatcher.BeginInvoke(new Action(() => DialogClosed(window, new DialogStateChangedEventArgs()))); } return (Task)window.Dispatcher.Invoke(new Func <Task>(() => { window.RemoveDialog(dialog); return HandleOverlayOnHide(settings, window); })); }).Unwrap()); }
private static ControlzEx.Theming.Theme DetectTheme(BaseMetroDialog dialog) { if (dialog == null) { return(null); } // first look for owner var window = dialog.OwningWindow ?? dialog.TryFindParent <MetroWindow>(); var theme = window != null?ThemeManager.Current.DetectTheme(window) : null; if (theme != null) { return(theme); } // second try, look for main window and then for current application if (Application.Current != null) { theme = Application.Current.MainWindow is null ? ThemeManager.Current.DetectTheme(Application.Current) : ThemeManager.Current.DetectTheme(Application.Current.MainWindow); if (theme != null) { return(theme); } } return(null); }
/// <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 static Task ShowMetroDialogAsync(this MetroWindow window, BaseMetroDialog dialog, MetroDialogSettings settings = null) { window.Dispatcher.VerifyAccess(); if (window.metroActiveDialogContainer.Children.Contains(dialog) || window.metroInactiveDialogContainer.Children.Contains(dialog)) { throw new InvalidOperationException("The provided dialog is already visible in the specified window."); } return(HandleOverlayOnShow(settings, window).ContinueWith(z => { dialog.Dispatcher.Invoke(new Action(() => { SizeChangedEventHandler sizeHandler = SetupAndOpenDialog(window, dialog); dialog.SizeChangedHandler = sizeHandler; })); }).ContinueWith(y => ((Task)dialog.Dispatcher.Invoke(new Func <Task>(() => dialog.WaitForLoadAsync().ContinueWith(x => { dialog.OnShown(); if (DialogOpened != null) { DialogOpened(window, new DialogStateChangedEventArgs()); } })))))); }
/// <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> /// <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 static Task HideMetroDialogAsync(this MetroWindow window, BaseMetroDialog dialog, MetroDialogSettings settings = null) { window.Dispatcher.VerifyAccess(); if (!window.metroDialogContainer.Children.Contains(dialog)) throw new InvalidOperationException("The provided dialog is not visible in the specified window."); window.SizeChanged -= dialog.SizeChangedHandler; dialog.OnClose(); Task closingTask = (Task)window.Dispatcher.Invoke(new Func<Task>(dialog._WaitForCloseAsync)); return closingTask.ContinueWith(a => { if (DialogClosed != null) { window.Dispatcher.BeginInvoke(new Action(() => DialogClosed(window, new DialogStateChangedEventArgs()))); } return (Task)window.Dispatcher.Invoke(new Func<Task>(() => { window.metroDialogContainer.Children.Remove(dialog); //remove the dialog from the container return HandleOverlayOnHide(settings, window); })); }).Unwrap(); }
public static BaseMetroDialog ShowDialogExternally(this BaseMetroDialog dialog) { Window window = DialogManager.SetupExternalDialogWindow(dialog); dialog.OnShown(); window.Show(); return(dialog); }
public static BaseMetroDialog ShowModalDialogExternally(this BaseMetroDialog dialog) { Window win = SetupExternalDialogWindow(dialog); dialog.OnShown(); win.ShowDialog(); return(dialog); }
/// <summary> /// Create and show an external modal dialog. /// </summary> /// <param name="dialog">The dialog which will be shown externally.</param> /// <param name="windowOwner">The owner for the external window. If it's null the main window will be use.</param> /// <returns>The given dialog.</returns> public static BaseMetroDialog ShowModalDialogExternally(this BaseMetroDialog dialog, [CanBeNull] Window windowOwner = null) { Window win = SetupExternalDialogWindow(dialog, windowOwner); dialog.OnShown(); win.ShowDialog(); return(dialog); }
private static void AddDialog(this MetroWindow window, BaseMetroDialog dialog) { UIElement uIElement = window.metroActiveDialogContainer.Children.Cast <UIElement>().SingleOrDefault <UIElement>(); if (uIElement != null) { window.metroActiveDialogContainer.Children.Remove(uIElement); window.metroInactiveDialogContainer.Children.Add(uIElement); } window.metroActiveDialogContainer.Children.Add(dialog); }
private static Window SetupExternalDialogWindow(BaseMetroDialog dialog, [CanBeNull] Window windowOwner = null) { var win = CreateExternalWindow(); win.Owner = windowOwner ?? Application.Current?.MainWindow; // Remove the border on left and right side win.BeginInvoke(x => { x.SetCurrentValue(Control.BorderThicknessProperty, new Thickness(0, x.BorderThickness.Top, 0, x.BorderThickness.Bottom)); if (x is MetroWindow metroWindow) { metroWindow.SetCurrentValue(MetroWindow.ResizeBorderThicknessProperty, new Thickness(0, metroWindow.ResizeBorderThickness.Top, 0, metroWindow.ResizeBorderThickness.Bottom)); } }, DispatcherPriority.Loaded); // Get the monitor working area var monitorWorkingArea = win.Owner.GetMonitorWorkSize(); if (monitorWorkingArea != default) { win.Width = monitorWorkingArea.Width; win.MinHeight = monitorWorkingArea.Height / 4.0; win.MaxHeight = monitorWorkingArea.Height; } else { win.Width = SystemParameters.PrimaryScreenWidth; win.MinHeight = SystemParameters.PrimaryScreenHeight / 4.0; win.MaxHeight = SystemParameters.PrimaryScreenHeight; } dialog.ParentDialogWindow = win; //THIS IS ONLY, I REPEAT, ONLY SET FOR EXTERNAL DIALOGS! win.Content = dialog; dialog.HandleThemeChange(); EventHandler closedHandler = null; closedHandler = (sender, args) => { win.Closed -= closedHandler; dialog.ParentDialogWindow = null; win.Content = null; }; win.Closed += closedHandler; win.SizeToContent = SizeToContent.Height; return(win); }
/// <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="BaseMetroDialog.WaitUntilUnloadedAsync"/> /// <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 static Task ShowMetroDialogAsync(this MetroWindow window, BaseMetroDialog dialog, MetroDialogSettings?settings = null) { if (window is null) { throw new ArgumentNullException(nameof(window)); } window.Dispatcher.VerifyAccess(); if (dialog is null) { throw new ArgumentNullException(nameof(dialog)); } if (window.metroActiveDialogContainer is null) { throw new InvalidOperationException("Active dialog container could not be found."); } if (window.metroInactiveDialogContainer is null) { throw new InvalidOperationException("Inactive dialog container could not be found."); } if (window.metroActiveDialogContainer.Children.Contains(dialog) || window.metroInactiveDialogContainer.Children.Contains(dialog)) { throw new InvalidOperationException("The provided dialog is already visible in the specified window."); } settings ??= (dialog.DialogSettings ?? window.MetroDialogOptions); return(HandleOverlayOnShow(settings, window).ContinueWith(z => { return (Task)window.Dispatcher.Invoke(new Func <Task>(() => { SetDialogFontSizes(settings, dialog); SizeChangedEventHandler sizeHandler = SetupAndOpenDialog(window, dialog); dialog.SizeChangedHandler = sizeHandler; return dialog.WaitForLoadAsync().ContinueWith(x => { dialog.OnShown(); if (DialogOpened != null) { window.Dispatcher.BeginInvoke(new Action(() => DialogOpened(window, new DialogStateChangedEventArgs()))); } }); })); }).Unwrap()); }
private static void AddDialog(this MetroWindow window, BaseMetroDialog dialog) { // if there's already an active dialog, move to the background var activeDialog = window.metroActiveDialogContainer.Children.Cast <UIElement>().SingleOrDefault(); if (activeDialog != null) { window.metroActiveDialogContainer.Children.Remove(activeDialog); window.metroInactiveDialogContainer.Children.Add(activeDialog); } window.metroActiveDialogContainer.Children.Add(dialog); //add the dialog to the container} }
/// <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> /// <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 static Task HideMetroDialogAsync(this MetroWindow window, BaseMetroDialog dialog) { window.Dispatcher.VerifyAccess(); if (!window.messageDialogContainer.Children.Contains(dialog)) { throw new InvalidOperationException("The provided dialog is not visible in the specified window."); } window.SizeChanged -= dialog.SizeChangedHandler; window.messageDialogContainer.Children.Remove(dialog); //remove the dialog from the container return(window.HideOverlayAsync()); }
private static Window SetupExternalDialogWindow(BaseMetroDialog dialog) { var win = new MetroWindow { ShowInTaskbar = false, ShowActivated = true, Topmost = true, ResizeMode = ResizeMode.NoResize, WindowStyle = WindowStyle.None, WindowStartupLocation = WindowStartupLocation.CenterScreen, ShowTitleBar = false, ShowCloseButton = false, WindowTransitionsEnabled = false }; try { win.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml") }); win.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml") }); win.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml") }); win.SetResourceReference(MetroWindow.GlowBrushProperty, "AccentColorBrush"); } catch (Exception) { } win.Width = SystemParameters.PrimaryScreenWidth; win.MinHeight = SystemParameters.PrimaryScreenHeight / 4.0; win.SizeToContent = SizeToContent.Height; dialog.ParentDialogWindow = win; //THIS IS ONLY, I REPEAT, ONLY SET FOR EXTERNAL DIALOGS! win.Content = dialog; EventHandler closedHandler = null; closedHandler = (sender, args) => { win.Closed -= closedHandler; dialog.ParentDialogWindow = null; win.Content = null; }; win.Closed += closedHandler; return(win); }
private static Window SetupExternalDialogWindow(BaseMetroDialog dialog) { MetroWindow metroWindow = new MetroWindow() { ShowInTaskbar = false, ShowActivated = true, Topmost = true, ResizeMode = ResizeMode.NoResize, WindowStyle = WindowStyle.None, WindowStartupLocation = WindowStartupLocation.CenterScreen, ShowTitleBar = false, ShowCloseButton = false, WindowTransitionsEnabled = false }; try { metroWindow.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri("pack://application:,,,/小喵谷登入器;component/Styles/Controls.xaml") }); metroWindow.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri("pack://application:,,,/小喵谷登入器;component/Styles/Fonts.xaml") }); metroWindow.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri("pack://application:,,,/小喵谷登入器;component/Styles/Colors.xaml") }); metroWindow.SetResourceReference(MetroWindow.GlowBrushProperty, "AccentColorBrush"); } catch (Exception exception) { } metroWindow.Width = SystemParameters.PrimaryScreenWidth; metroWindow.MinHeight = SystemParameters.PrimaryScreenHeight / 4; metroWindow.SizeToContent = SizeToContent.Height; dialog.ParentDialogWindow = metroWindow; metroWindow.Content = dialog; EventHandler parentDialogWindow = null; parentDialogWindow = (object sender, EventArgs e) => { metroWindow.Closed -= parentDialogWindow; dialog.ParentDialogWindow = null; metroWindow.Content = null; }; metroWindow.Closed += parentDialogWindow; return(metroWindow); }
private static Tuple <AppTheme, Accent> DetectTheme(BaseMetroDialog dialog) { Tuple <AppTheme, Accent> tuple; Tuple <AppTheme, Accent> tuple1; if (dialog == null) { return(null); } MetroWindow metroWindow = dialog.TryFindParent <MetroWindow>(); if (metroWindow != null) { tuple = ThemeManager.DetectAppStyle(metroWindow); } else { tuple = null; } Tuple <AppTheme, Accent> tuple2 = tuple; if (tuple2 != null && tuple2.Item2 != null) { return(tuple2); } if (Application.Current != null) { MetroWindow mainWindow = Application.Current.MainWindow as MetroWindow; if (mainWindow != null) { tuple1 = ThemeManager.DetectAppStyle(mainWindow); } else { tuple1 = null; } tuple2 = tuple1; if (tuple2 != null && tuple2.Item2 != null) { return(tuple2); } tuple2 = ThemeManager.DetectAppStyle(Application.Current); if (tuple2 != null && tuple2.Item2 != null) { return(tuple2); } } return(null); }
private static void SetDialogFontSizes(MetroDialogSettings settings, BaseMetroDialog dialog) { if (settings == null) { return; } if (!double.IsNaN(settings.DialogTitleFontSize)) { dialog.DialogTitleFontSize = settings.DialogTitleFontSize; } if (!double.IsNaN(settings.DialogMessageFontSize)) { dialog.DialogMessageFontSize = settings.DialogMessageFontSize; } }
private static Window SetupExternalDialogWindow(BaseMetroDialog dialog) { var win = new MetroWindow { ShowInTaskbar = false, ShowActivated = true, Topmost = true, ResizeMode = ResizeMode.NoResize, WindowStyle = WindowStyle.None, WindowStartupLocation = WindowStartupLocation.CenterScreen, ShowTitleBar = false, ShowCloseButton = false, WindowTransitionsEnabled = false, Background = dialog.Background }; try { win.GlowBrush = win.TryFindResource("AccentColorBrush") as SolidColorBrush; } catch (Exception) { } win.Width = SystemParameters.PrimaryScreenWidth; win.MinHeight = SystemParameters.PrimaryScreenHeight / 4.0; win.SizeToContent = SizeToContent.Height; var glowWindow = new GlowWindowBehavior(); glowWindow.Attach(win); dialog.ParentDialogWindow = win; //THIS IS ONLY, I REPEAT, ONLY SET FOR EXTERNAL DIALOGS! win.Content = dialog; EventHandler closedHandler = null; closedHandler = (sender, args) => { win.Closed -= closedHandler; dialog.ParentDialogWindow = null; win.Content = null; }; win.Closed += closedHandler; return(win); }
private static void AddDialog(this MetroWindow window, BaseMetroDialog dialog) { window.StoreFocus(); // if there's already an active dialog, move to the background var activeDialog = window.metroActiveDialogContainer.Children.OfType <BaseMetroDialog>().SingleOrDefault(); if (activeDialog != null) { window.metroActiveDialogContainer.Children.Remove(activeDialog); window.metroInactiveDialogContainer.Children.Add(activeDialog); } window.metroActiveDialogContainer.Children.Add(dialog); //add the dialog to the container} window.SetValue(MetroWindow.IsAnyDialogOpenPropertyKey, BooleanBoxes.TrueBox); }
public static Task <object> ShowBaseMetroDialog(this MetroWindow window, BaseMetroDialog dialog) { window.Dispatcher.VerifyAccess(); return(HandleOverlayOnShow(null, window).ContinueWith(z => { return (Task <object>)window.Dispatcher.Invoke(new Func <Task <object> >(() => { SizeChangedEventHandler sizeHandler = SetupAndOpenDialog(window, dialog); dialog.SizeChangedHandler = sizeHandler; return dialog.WaitForLoadAsync().ContinueWith(x => { if (DialogOpened != null) { window.Dispatcher.BeginInvoke(new Action(() => DialogOpened(window, new DialogStateChangedEventArgs()))); } return dialog.WaitForButtonPressAsync().ContinueWith(y => { //once a button as been clicked, begin removing the dialog. dialog.OnClose(); if (DialogClosed != null) { window.Dispatcher.BeginInvoke(new Action(() => DialogClosed(window, new DialogStateChangedEventArgs()))); } Task closingTask = (Task)window.Dispatcher.Invoke(new Func <Task>(() => dialog._WaitForCloseAsync())); return closingTask.ContinueWith(a => { return ((Task)window.Dispatcher.Invoke(new Func <Task>(() => { window.SizeChanged -= sizeHandler; window.RemoveDialog(dialog); return HandleOverlayOnHide(null, window); }))).ContinueWith(y3 => y).Unwrap(); }); }).Unwrap(); }).Unwrap().Unwrap(); })); }).Unwrap()); }
private static void RemoveDialog(this MetroWindow window, BaseMetroDialog dialog) { if (!window.metroActiveDialogContainer.Children.Contains(dialog)) { window.metroInactiveDialogContainer.Children.Remove(dialog); } else { window.metroActiveDialogContainer.Children.Remove(dialog); UIElement uIElement = window.metroInactiveDialogContainer.Children.Cast <UIElement>().LastOrDefault <UIElement>(); if (uIElement != null) { window.metroInactiveDialogContainer.Children.Remove(uIElement); window.metroActiveDialogContainer.Children.Add(uIElement); return; } } }
/// <summary> /// Adds a Metro Dialog instance to the specified window and makes it visible. /// </summary> /// <param name="window">The owning window of the dialog.</param> /// <param name="title">The title to be set in the dialog.</param> /// <param name="dialog">The dialog instance itself.</param> /// <returns>A task representing the operation.</returns> /// <exception cref="InvalidOperationException">The <paramref name="dialog"/> is already visible in the window.</exception> public static Task ShowMetroDialogAsync(this MetroWindow window, BaseMetroDialog dialog) { window.Dispatcher.VerifyAccess(); if (window.messageDialogContainer.Children.Contains(dialog)) { throw new InvalidOperationException("The provided dialog is already visible in the specified window."); } return(window.ShowOverlayAsync().ContinueWith(z => { dialog.Dispatcher.Invoke(new Action(() => { SizeChangedEventHandler sizeHandler = SetupAndOpenDialog(window, dialog); dialog.SizeChangedHandler = sizeHandler; })); }).ContinueWith(y => ((Task)dialog.Dispatcher.Invoke(new Func <Task>(() => dialog.WaitForLoadAsync()))))); }
public static Task HideMetroDialogAsync(this MetroWindow window, BaseMetroDialog dialog, MetroDialogSettings settings = null) { Action action1 = null; Func <Task> func2 = null; window.Dispatcher.VerifyAccess(); if (!window.metroActiveDialogContainer.Children.Contains(dialog) && !window.metroInactiveDialogContainer.Children.Contains(dialog)) { throw new InvalidOperationException("The provided dialog is not visible in the specified window."); } window.SizeChanged -= dialog.SizeChangedHandler; dialog.OnClose(); Task task = window.Dispatcher.Invoke <Task>(new Func <Task>(dialog._WaitForCloseAsync)); return(task.ContinueWith <Task>((Task a) => { if (DialogManager.DialogClosed != null) { Dispatcher dispatcher = window.Dispatcher; Action u003cu003e9_1 = action1; if (u003cu003e9_1 == null) { Action dialogClosed = () => DialogManager.DialogClosed(window, new DialogStateChangedEventArgs()); Action action = dialogClosed; action1 = dialogClosed; u003cu003e9_1 = action; } dispatcher.BeginInvoke(u003cu003e9_1, new object[0]); } Dispatcher dispatcher1 = window.Dispatcher; Func <Task> u003cu003e9_2 = func2; if (u003cu003e9_2 == null) { Func <Task> func = () => { window.RemoveDialog(dialog); return DialogManager.HandleOverlayOnHide(settings, window); }; Func <Task> func1 = func; func2 = func; u003cu003e9_2 = func1; } return dispatcher1.Invoke <Task>(u003cu003e9_2); }).Unwrap()); }
private static void RemoveDialog(this MetroWindow window, BaseMetroDialog dialog) { if (window.metroActiveDialogContainer.Children.Contains(dialog)) { window.metroActiveDialogContainer.Children.Remove(dialog); //remove the dialog from the container // if there's an inactive dialog, bring it to the front var dlg = window.metroInactiveDialogContainer.Children.Cast <UIElement>().LastOrDefault(); if (dlg != null) { window.metroInactiveDialogContainer.Children.Remove(dlg); window.metroActiveDialogContainer.Children.Add(dlg); } } else { window.metroInactiveDialogContainer.Children.Remove(dialog); } }
public static SizeChangedEventHandler SetupAndOpenDialog(MetroWindow window, BaseMetroDialog dialog) { dialog.SetValue(Panel.ZIndexProperty, (int)window.overlayBox.GetValue(Panel.ZIndexProperty) + 1); dialog.MinHeight = window.ActualHeight / 4.0; dialog.MaxHeight = window.ActualHeight; SizeChangedEventHandler sizeHandler = (sender, args) => { dialog.MinHeight = window.ActualHeight / 4.0; dialog.MaxHeight = window.ActualHeight; }; window.SizeChanged += sizeHandler; window.metroDialogContainer.Children.Add(dialog); //add the dialog to the container dialog.OnShown(); return sizeHandler; }
private static void RemoveDialog(this MetroWindow window, BaseMetroDialog dialog) { if (window.metroActiveDialogContainer.Children.Contains(dialog)) { window.metroActiveDialogContainer.Children.Remove(dialog); //remove the dialog from the container // if there's an inactive dialog, bring it to the front var dlg = window.metroInactiveDialogContainer.Children.OfType <BaseMetroDialog>().LastOrDefault(); if (dlg != null) { window.metroInactiveDialogContainer.Children.Remove(dlg); window.metroActiveDialogContainer.Children.Add(dlg); } } else { window.metroInactiveDialogContainer.Children.Remove(dialog); } window.SetValue(MetroWindow.IsAnyDialogOpenPropertyKey, BooleanBoxes.Box(window.metroActiveDialogContainer.Children.Count > 0)); }
private static Window SetupExternalDialogWindow(BaseMetroDialog dialog) { var win = CreateExternalWindow(); try { win.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml") }); win.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml") }); win.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml") }); win.SetResourceReference(MetroWindow.GlowBrushProperty, "AccentColorBrush"); } catch (Exception) { } win.Width = SystemParameters.PrimaryScreenWidth; win.MinHeight = SystemParameters.PrimaryScreenHeight / 4.0; win.SizeToContent = SizeToContent.Height; dialog.ParentDialogWindow = win; //THIS IS ONLY, I REPEAT, ONLY SET FOR EXTERNAL DIALOGS! win.Content = dialog; EventHandler closedHandler = null; closedHandler = (sender, args) => { win.Closed -= closedHandler; dialog.ParentDialogWindow = null; win.Content = null; }; win.Closed += closedHandler; return(win); }
private static MahApps.Metro.Theme DetectTheme(BaseMetroDialog dialog) { if (dialog == null) { return(null); } // first look for owner var window = dialog.OwningWindow ?? dialog.TryFindParent <MetroWindow>(); var theme = window != null?ThemeManager.DetectTheme(window) : null; if (theme != null) { return(theme); } // second try, look for main window if (Application.Current != null) { var mainWindow = Application.Current.MainWindow as MetroWindow; theme = mainWindow != null?ThemeManager.DetectTheme(mainWindow) : null; if (theme != null) { return(theme); } // oh no, now look at application resource theme = ThemeManager.DetectTheme(Application.Current); if (theme != null) { return(theme); } } return(null); }
private static Tuple <AppTheme, Accent> DetectTheme(BaseMetroDialog dialog) { if (dialog == null) { return(null); } // first look for owner var window = dialog.TryFindParent <MetroWindow>(); var theme = window != null?ThemeManager.DetectAppStyle(window) : null; if (theme != null && theme.Item2 != null) { return(theme); } // second try, look for main window if (Application.Current != null) { var mainWindow = Application.Current.MainWindow as MetroWindow; theme = mainWindow != null?ThemeManager.DetectAppStyle(mainWindow) : null; if (theme != null && theme.Item2 != null) { return(theme); } // oh no, now look at application resource theme = ThemeManager.DetectAppStyle(Application.Current); if (theme != null && theme.Item2 != null) { return(theme); } } return(null); }
private static SizeChangedEventHandler SetupAndOpenDialog(MetroWindow window, string title, BaseMetroDialog dialog) { dialog.SetValue(Panel.ZIndexProperty, (int)window.overlayBox.GetValue(Panel.ZIndexProperty) + 1); dialog.MinHeight = window.ActualHeight / 4.0; dialog.Title = title; SizeChangedEventHandler sizeHandler = null; //an event handler for auto resizing an open dialog. sizeHandler = new SizeChangedEventHandler((sender, args) => { dialog.MinHeight = window.ActualHeight / 4.0; }); window.SizeChanged += sizeHandler; //window.overlayBox.Visibility = Visibility.Visible; //activate the overlay effect window.messageDialogContainer.Children.Add(dialog); //add the dialog to the container dialog.OnShown(); if (window.TextBlockStyle != null && !dialog.Resources.Contains(typeof(TextBlock))) { dialog.Resources.Add(typeof(TextBlock), window.TextBlockStyle); } return sizeHandler; }
/// <summary> /// Adds a Metro Dialog instance to the specified window and makes it visible. /// </summary> /// <param name="window">The owning window of the dialog.</param> /// <param name="title">The title to be set in the dialog.</param> /// <param name="dialog">The dialog instance itself.</param> /// <returns>A task representing the operation.</returns> public static Task ShowMetroDialogAsync(this MetroWindow window, string title, BaseMetroDialog dialog) { window.Dispatcher.VerifyAccess(); if (window.messageDialogContainer.Children.Contains(dialog)) throw new Exception("The provided dialog is already visible in the specified window."); return window.ShowOverlayAsync().ContinueWith(z => { dialog.Dispatcher.Invoke(new Action(() => { SizeChangedEventHandler sizeHandler = SetupAndOpenDialog(window, title, dialog); dialog.SizeChangedHandler = sizeHandler; })); }).ContinueWith(y => ((Task)dialog.Dispatcher.Invoke(new Func<Task>(() => dialog.WaitForLoadAsync())))).Unwrap(); }
/// <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> /// <returns>A task representing the operation.</returns> public static Task HideMetroDialogAsync(this MetroWindow window, BaseMetroDialog dialog) { window.Dispatcher.VerifyAccess(); if (!window.messageDialogContainer.Children.Contains(dialog)) throw new Exception("The provided dialog is not visible in the specified window."); window.SizeChanged -= dialog.SizeChangedHandler; window.messageDialogContainer.Children.Remove(dialog); //remove the dialog from the container return window.HideOverlayAsync(); }
private static Window SetupExternalDialogWindow(BaseMetroDialog dialog) { MetroWindow win = new MetroWindow(); win.ShowInTaskbar = false; win.ShowActivated = true; win.Topmost = true; win.ResizeMode = ResizeMode.NoResize; win.WindowStyle = WindowStyle.None; win.WindowStartupLocation = WindowStartupLocation.CenterScreen; win.ShowTitleBar = false; win.ShowCloseButton = false; win.WindowTransitionsEnabled = false; win.Background = dialog.Background; try { win.GlowBrush = win.TryFindResource("AccentColorBrush") as SolidColorBrush; } catch (Exception) { } win.Width = SystemParameters.PrimaryScreenWidth; win.MinHeight = SystemParameters.PrimaryScreenHeight / 4.0; win.SizeToContent = SizeToContent.Height; GlowWindowBehavior glowWindow = new GlowWindowBehavior(); glowWindow.Attach(win); dialog.ParentDialogWindow = win; //THIS IS ONLY, I REPEAT, ONLY SET FOR EXTERNAL DIALOGS! win.Content = dialog; EventHandler closedHandler = null; closedHandler = (sender, args) => { win.Closed -= closedHandler; dialog.ParentDialogWindow = null; win.Content = null; }; win.Closed += closedHandler; return win; }
public MetroDialogAutomationPeer(BaseMetroDialog owner) : base(owner) { }
/// <summary> /// Adds a Metro Dialog instance to the specified window and makes it visible. /// </summary> /// <param name="window">The owning window of the dialog.</param> /// <param name="title">The title to be set in the dialog.</param> /// <param name="dialog">The dialog instance itself.</param> /// <returns>A task representing the operation.</returns> /// <exception cref="InvalidOperationException">The <paramref name="dialog"/> is already visible in the window.</exception> public static Task ShowMetroDialogAsync(this MetroWindow window, BaseMetroDialog dialog) { window.Dispatcher.VerifyAccess(); if (window.metroDialogContainer.Children.Contains(dialog)) throw new InvalidOperationException("The provided dialog is already visible in the specified window."); return window.ShowOverlayAsync().ContinueWith(z => { dialog.Dispatcher.Invoke(new Action(() => { SizeChangedEventHandler sizeHandler = SetupAndOpenDialog(window, dialog); dialog.SizeChangedHandler = sizeHandler; })); }).ContinueWith(y => ((Task)dialog.Dispatcher.Invoke(new Func<Task>(() => dialog.WaitForLoadAsync().ContinueWith(x => { dialog.OnShown(); if (DialogOpened != null) { DialogOpened(window, new DialogStateChangedEventArgs() { }); } }))))); }
private static SizeChangedEventHandler SetupAndOpenDialog(MetroWindow window, BaseMetroDialog dialog) { dialog.SetValue(Panel.ZIndexProperty, (int)window.overlayBox.GetValue(Panel.ZIndexProperty) + 1); dialog.MinHeight = window.ActualHeight / 4.0; dialog.MaxHeight = window.ActualHeight; SizeChangedEventHandler sizeHandler = null; //an event handler for auto resizing an open dialog. sizeHandler = new SizeChangedEventHandler((sender, args) => { dialog.MinHeight = window.ActualHeight / 4.0; dialog.MaxHeight = window.ActualHeight; }); window.SizeChanged += sizeHandler; //window.overlayBox.Visibility = Visibility.Visible; //activate the overlay effect window.metroDialogContainer.Children.Add(dialog); //add the dialog to the container dialog.OnShown(); return sizeHandler; }
public async void ShowCameraPositioningDialog() { _dialog = new CameraPositioningCalibrationView(_parentWindow) { DataContext = new CameraPositioningCalibrationViewModel(_viewModel.CamerasModel) }; await _parentWindow.ShowMetroDialogAsync(_dialog); }
public async void ShowDialog() { _dialog = new CameraCalibrationView(_parentWindow) { DataContext = new CameraCalibrationViewModel { Camera = _viewModel.Camera } }; await _parentWindow.ShowMetroDialogAsync(_dialog); }
private static SizeChangedEventHandler SetupAndOpenDialog(MetroWindow window, BaseMetroDialog dialog) { dialog.SetValue(Panel.ZIndexProperty, (int)window.overlayBox.GetValue(Panel.ZIndexProperty) + 1); dialog.MinHeight = window.ActualHeight / 4.0; dialog.MaxHeight = window.ActualHeight; SizeChangedEventHandler sizeHandler = (sender, args) => { dialog.MinHeight = window.ActualHeight / 4.0; dialog.MaxHeight = window.ActualHeight; }; window.SizeChanged += sizeHandler; window.AddDialog(dialog); dialog.OnShown(); return(sizeHandler); }
public async void ShowStereoCameraCalibrationDialog() { _viewModel.DoToggleCamera(false); _viewModel.DoToggleTracking(false); _dialog = new StereoCameraCalibrationView(_parentWindow) { DataContext = new StereoCameraCalibrationViewModel(_viewModel.CamerasModel.Cameras) }; await _parentWindow.ShowMetroDialogAsync(_dialog); }
private async Task DialogMessageHandleAsync(DialogMessage obj) { if (obj.ActType == ActionType.Close) { Application.Current.Shutdown(); } else { switch (obj.DlgType) { case DialogType.Login: case DialogType.About: if (obj.ActType == ActionType.Show) { var viewModelLocator = (ViewModelLocator)App.Current.Resources["Locator"]; if (viewModelLocator == null) return; _currentDialog = (BaseMetroDialog)App.Current.Resources[obj.DialogTemplateKey]; _currentDialog.DataContext = obj.DlgType == DialogType.Login ? viewModelLocator.TokenDialog : viewModelLocator.AboutDialog; await this.ShowMetroDialogAsync(_currentDialog); } else if (_currentDialog != null) { await this.HideMetroDialogAsync(_currentDialog); } break; case DialogType.Close: if (_shutdown) return; var settings = new MetroDialogSettings() { AffirmativeButtonText = Properties.Resources.Close, NegativeButtonText = Properties.Resources.Cancel, AnimateShow = true, AnimateHide = false }; var result = await this.ShowMessageAsync( Properties.Resources.TitleDlgExitApp, Properties.Resources.QuestionExitApp, MessageDialogStyle.AffirmativeAndNegative, settings); if (result == MessageDialogResult.Affirmative) { await ViewModelLocator.ClearAsync(); ViewModelLocator.Cleanup(); _shutdown = true; Application.Current.Shutdown(); } break; case DialogType.Notification: await this.ShowMessageAsync("Notification", "Test"); break; default: break; } } }
static ReactiveCommand<bool?> CreateCommand(BaseMetroDialog dialog, MetroWindow window, TaskCompletionSource<bool?> tcs) { var command = ReactiveCommand.CreateAsyncTask(async x => { await window.HideMetroDialogAsync(dialog); return (bool?) x; }); SetupCommand(tcs, command); return command; }
private void HandleTheme() { if (this.DialogSettings != null) { Tuple <AppTheme, Accent> tuple = BaseMetroDialog.DetectTheme(this); if (DesignerProperties.GetIsInDesignMode(this) || tuple == null) { return; } AppTheme item1 = tuple.Item1; Accent item2 = tuple.Item2; switch (this.DialogSettings.ColorScheme) { case MetroDialogColorScheme.Theme: { ThemeManager.ChangeAppStyle(base.Resources, item2, item1); DependencyProperty backgroundProperty = Control.BackgroundProperty; Window owningWindow = this.OwningWindow; if (owningWindow == null) { owningWindow = Application.Current.MainWindow; } base.SetValue(backgroundProperty, ThemeManager.GetResourceFromAppStyle(owningWindow, "WhiteColorBrush")); DependencyProperty foregroundProperty = Control.ForegroundProperty; Window mainWindow = this.OwningWindow; if (mainWindow == null) { mainWindow = Application.Current.MainWindow; } base.SetValue(foregroundProperty, ThemeManager.GetResourceFromAppStyle(mainWindow, "BlackBrush")); break; } case MetroDialogColorScheme.Accented: { ThemeManager.ChangeAppStyle(base.Resources, item2, item1); DependencyProperty dependencyProperty = Control.BackgroundProperty; Window window = this.OwningWindow; if (window == null) { window = Application.Current.MainWindow; } base.SetValue(dependencyProperty, ThemeManager.GetResourceFromAppStyle(window, "HighlightBrush")); DependencyProperty foregroundProperty1 = Control.ForegroundProperty; Window owningWindow1 = this.OwningWindow; if (owningWindow1 == null) { owningWindow1 = Application.Current.MainWindow; } base.SetValue(foregroundProperty1, ThemeManager.GetResourceFromAppStyle(owningWindow1, "IdealForegroundColorBrush")); break; } case MetroDialogColorScheme.Inverted: { AppTheme inverseAppTheme = ThemeManager.GetInverseAppTheme(item1); if (inverseAppTheme == null) { throw new InvalidOperationException("The inverse dialog theme only works if the window theme abides the naming convention. See ThemeManager.GetInverseAppTheme for more infos"); } ThemeManager.ChangeAppStyle(base.Resources, item2, inverseAppTheme); DependencyProperty backgroundProperty1 = Control.BackgroundProperty; Window mainWindow1 = this.OwningWindow; if (mainWindow1 == null) { mainWindow1 = Application.Current.MainWindow; } base.SetValue(backgroundProperty1, ThemeManager.GetResourceFromAppStyle(mainWindow1, "BlackColorBrush")); DependencyProperty dependencyProperty1 = Control.ForegroundProperty; Window window1 = this.OwningWindow; if (window1 == null) { window1 = Application.Current.MainWindow; } base.SetValue(dependencyProperty1, ThemeManager.GetResourceFromAppStyle(window1, "WhiteColorBrush")); break; } } } if (this.ParentDialogWindow != null) { this.ParentDialogWindow.SetValue(Control.BackgroundProperty, base.Background); Window owningWindow2 = this.OwningWindow; if (owningWindow2 == null) { owningWindow2 = Application.Current.MainWindow; } object resourceFromAppStyle = ThemeManager.GetResourceFromAppStyle(owningWindow2, "AccentColorBrush"); if (resourceFromAppStyle != null) { this.ParentDialogWindow.SetValue(MetroWindow.GlowBrushProperty, resourceFromAppStyle); } } }
private static Tuple<AppTheme, Accent> DetectTheme(BaseMetroDialog dialog) { if (dialog == null) return null; // first look for owner var window = dialog.TryFindParent<MetroWindow>(); var theme = window != null ? ThemeManager.DetectAppStyle(window) : null; if (theme != null && theme.Item2 != null) return theme; // second try, look for main window if (Application.Current != null) { var mainWindow = Application.Current.MainWindow as MetroWindow; theme = mainWindow != null ? ThemeManager.DetectAppStyle(mainWindow) : null; if (theme != null && theme.Item2 != null) return theme; // oh no, now look at application resource theme = ThemeManager.DetectAppStyle(Application.Current); if (theme != null && theme.Item2 != null) return theme; } return null; }
static async Task<bool?> HandleMetroDialog(IMetroDialog model, BaseMetroDialog dialog) { var window = (MetroWindow) Application.Current.MainWindow; var tcs = new TaskCompletionSource<bool?>(); model.Close = CreateCommand(dialog, window, tcs); await window.ShowMetroDialogAsync(dialog); return await tcs.Task; }