예제 #1
0
        private static void RemoveDialog(this CrystalWindow window, CrystalDialogBase dialog)
        {
            if (window.crystalActiveDialogContainer is null)
            {
                throw new InvalidOperationException("Active dialog container could not be found.");
            }

            if (window.crystalInactiveDialogContainer is null)
            {
                throw new InvalidOperationException("Inactive dialog container could not be found.");
            }

            if (window.crystalActiveDialogContainer.Children.Contains(dialog))
            {
                window.crystalActiveDialogContainer.Children.Remove(dialog); //remove the dialog from the container

                // if there's an inactive dialog, bring it to the front
                var dlg = window.crystalInactiveDialogContainer.Children.OfType <CrystalDialogBase>().LastOrDefault();
                if (dlg != null)
                {
                    window.crystalInactiveDialogContainer.Children.Remove(dlg);
                    window.crystalActiveDialogContainer.Children.Add(dlg);
                }
            }
            else
            {
                window.crystalInactiveDialogContainer.Children.Remove(dialog);
            }

            window.SetValue(CrystalWindow.IsAnyDialogOpenPropertyKey, BooleanBoxes.Box(window.crystalActiveDialogContainer.Children.Count > 0));
        }
예제 #2
0
        /// <summary>
        /// Creates a InputDialog outside of the current window.
        /// </summary>
        /// <param name="window">The CrystalWindow</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 crystal dialog settings.</param>
        /// <returns>The text that was entered or null (Nothing in Visual Basic) if the user cancelled the operation.</returns>
        public static string?ShowModalInputExternal(this CrystalWindow window, string title, string message, CrystalDialogSettings?settings = null)
        {
            var win = CreateModalExternalWindow(window);

            settings ??= window.CrystalDialogOptions;

            //create the dialog control
            var dialog = new InputDialog(win, 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(settings, window);
            win.ShowDialog();
            HandleOverlayOnHide(settings, window);
            return(result);
        }
예제 #3
0
        /// <summary>
        /// Creates a MessageDialog outside of the current window.
        /// </summary>
        /// <param name="window">The CrystalWindow</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 crystal dialog settings.</param>
        /// <returns>A task promising the result of which button was pressed.</returns>
        public static MessageDialogResult ShowModalMessageExternal(this CrystalWindow window, string title, string message, MessageDialogStyle style = MessageDialogStyle.Affirmative, CrystalDialogSettings?settings = null)
        {
            var win = CreateModalExternalWindow(window);

            settings ??= window.CrystalDialogOptions;

            //create the dialog control
            var dialog = new MessageDialog(win, settings)
            {
                Message     = message,
                Title       = title,
                ButtonStyle = style
            };

            SetDialogFontSizes(settings, dialog);

            win.Content = dialog;

            MessageDialogResult result = MessageDialogResult.Affirmative;

            dialog.WaitForButtonPressAsync()
            .ContinueWith(task =>
            {
                result = task.Result;
                win.Invoke(win.Close);
            });

            HandleOverlayOnShow(settings, window);
            win.ShowDialog();
            HandleOverlayOnHide(settings, window);
            return(result);
        }
예제 #4
0
        private static void AddDialog(this CrystalWindow window, CrystalDialogBase dialog)
        {
            if (window.crystalActiveDialogContainer is null)
            {
                throw new InvalidOperationException("Active dialog container could not be found.");
            }

            if (window.crystalInactiveDialogContainer is null)
            {
                throw new InvalidOperationException("Inactive dialog container could not be found.");
            }

            window.StoreFocus();

            // if there's already an active dialog, move to the background
            var activeDialog = window.crystalActiveDialogContainer.Children.OfType <CrystalDialogBase>().SingleOrDefault();

            if (activeDialog != null)
            {
                window.crystalActiveDialogContainer.Children.Remove(activeDialog);
                window.crystalInactiveDialogContainer.Children.Add(activeDialog);
            }

            window.crystalActiveDialogContainer.Children.Add(dialog); //add the dialog to the container}

            window.SetValue(CrystalWindow.IsAnyDialogOpenPropertyKey, BooleanBoxes.TrueBox);
        }
예제 #5
0
        private static void ChangeAllWindowButtonCommandsBrush(this CrystalWindow window, Brush? foregroundBrush, Theme? currentAppTheme, FlyoutTheme flyoutTheme = FlyoutTheme.Adapt, Position position = Position.Top)
        {
            if (position == Position.Right || position == Position.Top)
              {
            if (foregroundBrush is null)
            {
              window.WindowButtonCommands?.ClearValue(Control.ForegroundProperty);
            }

            // set the theme based on color lightness
            // otherwise set the theme based on current application or window theme
            var theme = currentAppTheme != null && currentAppTheme.BaseColorScheme == ThemeManager.BaseColorDark
            ? ThemeManager.BaseColorDark
            : ThemeManager.BaseColorLight;

            theme = flyoutTheme switch
            {
              FlyoutTheme.Light => ThemeManager.BaseColorLight,
              FlyoutTheme.Dark => ThemeManager.BaseColorDark,
              FlyoutTheme.Inverse => theme == ThemeManager.BaseColorLight ? ThemeManager.BaseColorDark : ThemeManager.BaseColorLight,
              _ => theme
            };

            window.WindowButtonCommands?.SetValue(WindowButtonCommands.ThemeProperty, theme);

            // clear or set the foreground property
            if (foregroundBrush != null)
            {
              window.WindowButtonCommands?.SetValue(Control.ForegroundProperty, foregroundBrush);
            }
              }
        }
예제 #6
0
        public static void UpdateWindowCommandsForFlyout(this CrystalWindow window, Flyout flyout)
        {
            var currentTheme = GetCurrentTheme(window);

              window.ChangeAllWindowCommandsBrush(window.OverrideDefaultWindowCommandsBrush, currentTheme);
              window.ChangeAllWindowButtonCommandsBrush(window.OverrideDefaultWindowCommandsBrush ?? flyout.Foreground, currentTheme, flyout.Theme, flyout.Position);
        }
예제 #7
0
        /// <summary>
        /// Adds a Crystal Dialog instance of the given type to the specified window and makes it visible asynchronously.
        /// If you want to wait until the user has closed the dialog, use <see cref="CrystalDialogBase.WaitUntilUnloadedAsync"/>
        /// <para>You have to close the resulting dialog yourself with <see cref="HideCrystalDialogAsync"/>.</para>
        /// </summary>
        /// <param name="window">The owning window of the dialog.</param>
        /// <param name="settings">An optional pre-defined settings instance.</param>
        /// <returns>A task with the dialog representing the operation.</returns>
        public static Task <TDialog> ShowCrystalDialogAsync <TDialog>([NotNull] this CrystalWindow window, CrystalDialogSettings?settings = null)
            where TDialog : CrystalDialogBase
        {
            if (window is null)
            {
                throw new ArgumentNullException(nameof(window));
            }

            window.Dispatcher.VerifyAccess();

            var dialog = (TDialog)Activator.CreateInstance(typeof(TDialog), window, settings) !;

            return(HandleOverlayOnShow(dialog.DialogSettings, window).ContinueWith(z =>
            {
                return window.Dispatcher.Invoke(new Func <Task <TDialog> >(() =>
                {
                    SetDialogFontSizes(dialog.DialogSettings, 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())));
                        }
                    }).ContinueWith(x => dialog);
                }));
            }).Unwrap());
        }
예제 #8
0
        public static void ResetAllWindowCommandsBrush(this CrystalWindow window)
        {
            var currentTheme = GetCurrentTheme(window);

              window.ChangeAllWindowCommandsBrush(window.OverrideDefaultWindowCommandsBrush, currentTheme);
              window.ChangeAllWindowButtonCommandsBrush(window.OverrideDefaultWindowCommandsBrush, currentTheme);
        }
예제 #9
0
        private static Task HandleOverlayOnShow(CrystalDialogSettings?settings, CrystalWindow window)
        {
            return(Task.Factory.StartNew(() =>
            {
                window.Invoke(() =>
                {
                    var isCloseButtonEnabled = window.ShowDialogsOverTitleBar || settings is null || settings.OwnerCanCloseWithDialog;
                    window.SetValue(CrystalWindow.IsCloseButtonEnabledWithDialogPropertyKey, BooleanBoxes.Box(isCloseButtonEnabled));
                });
            })
                   .ContinueWith(task =>
            {
                return window.Invoke(() =>
                {
                    if (window.crystalActiveDialogContainer is null)
                    {
                        throw new InvalidOperationException("Active dialog container could not be found.");
                    }

                    if (!window.crystalActiveDialogContainer.Children.OfType <CrystalDialogBase>().Any())
                    {
                        return (settings is null || settings.AnimateShow ? window.ShowOverlayAsync() : Task.Factory.StartNew(() => window.Dispatcher.Invoke(new Action(window.ShowOverlay))));
                    }
                    else
                    {
                        var tcs = new TaskCompletionSource <object>();
                        tcs.SetResult(null !);
                        return tcs.Task;
                    }
                });
            })
                   .Unwrap());
        }
예제 #10
0
        /// <summary>
        /// Creates a LoginDialog outside of the current window.
        /// </summary>
        /// <param name="window">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="settings">Optional settings that override the global crystal dialog settings.</param>
        /// <returns>The text that was entered or null (Nothing in Visual Basic) if the user cancelled the operation.</returns>
        public static LoginDialogData?ShowModalLoginExternal(this CrystalWindow window, string title, string message, LoginDialogSettings?settings = null)
        {
            var win = CreateModalExternalWindow(window);

            settings ??= new LoginDialogSettings();

            //create the dialog control
            LoginDialog dialog = new LoginDialog(win, settings)
            {
                Title   = title,
                Message = message
            };

            SetDialogFontSizes(settings, dialog);

            win.Content = dialog;

            LoginDialogData?result = null;

            dialog.WaitForButtonPressAsync()
            .ContinueWith(task =>
            {
                result = task.Result;
                win.Invoke(win.Close);
            });

            HandleOverlayOnShow(settings, window);
            win.ShowDialog();
            HandleOverlayOnHide(settings, window);
            return(result);
        }
예제 #11
0
        /// <summary>
        /// Creates a InputDialog inside of the current window.
        /// </summary>
        /// <param name="window">The CrystalWindow</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 crystal dialog settings.</param>
        /// <returns>The text that was entered or null (Nothing in Visual Basic) if the user cancelled the operation.</returns>
        public static Task <string?> ShowInputAsync(this CrystalWindow window, string title, string message, CrystalDialogSettings?settings = null)
        {
            window.Dispatcher.VerifyAccess();

            settings ??= window.CrystalDialogOptions;

            return(HandleOverlayOnShow(settings, window).ContinueWith(z =>
            {
                return window.Dispatcher.Invoke(new Func <Task <string?> >(() =>
                {
                    //create the dialog control
                    var dialog = new InputDialog(window, settings)
                    {
                        Title = title,
                        Message = message,
                        Input = settings?.DefaultText,
                    };

                    SetDialogFontSizes(settings, dialog);

                    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 = window.Dispatcher.Invoke(new Func <Task>(() => dialog.WaitForCloseAsync()));
                            return closingTask.ContinueWith(a =>
                            {
                                return window.Dispatcher.Invoke(new Func <Task>(() =>
                                {
                                    window.SizeChanged -= sizeHandler;

                                    window.RemoveDialog(dialog);

                                    return HandleOverlayOnHide(settings, window);
                                })).ContinueWith(y3 => y).Unwrap();
                            });
                        }).Unwrap();
                    }).Unwrap().Unwrap();
                }));
            }).Unwrap());
        }
예제 #12
0
        /// <summary>
        /// Creates a ProgressDialog inside of the current window.
        /// </summary>
        /// <param name="window">The CrystalWindow</param>
        /// <param name="title">The title of the ProgressDialog.</param>
        /// <param name="message">The message within the ProgressDialog.</param>
        /// <param name="isCancelable">Determines if the cancel button is visible.</param>
        /// <param name="settings">Optional Settings that override the global crystal dialog settings.</param>
        /// <returns>A task promising the instance of ProgressDialogController for this operation.</returns>
        public static Task <ProgressDialogController> ShowProgressAsync(this CrystalWindow window, string title, string message, bool isCancelable = false, CrystalDialogSettings?settings = null)
        {
            window.Dispatcher.VerifyAccess();

            settings ??= window.CrystalDialogOptions;

            return(HandleOverlayOnShow(settings, window).ContinueWith(z =>
            {
                return window.Dispatcher.Invoke(new Func <Task <ProgressDialogController> >(() =>
                {
                    //create the dialog control
                    var dialog = new ProgressDialog(window, settings)
                    {
                        Title = title,
                        Message = message,
                        IsCancelable = isCancelable
                    };

                    SetDialogFontSizes(settings, dialog);

                    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 new ProgressDialogController(dialog, () =>
                        {
                            dialog.OnClose();

                            if (DialogClosed != null)
                            {
                                window.Dispatcher.BeginInvoke(new Action(() => DialogClosed(window, new DialogStateChangedEventArgs())));
                            }

                            Task closingTask = window.Dispatcher.Invoke(new Func <Task>(() => dialog.WaitForCloseAsync()));
                            return closingTask.ContinueWith(a =>
                            {
                                return window.Dispatcher.Invoke(new Func <Task>(() =>
                                {
                                    window.SizeChanged -= sizeHandler;

                                    window.RemoveDialog(dialog);

                                    return HandleOverlayOnHide(settings, window);
                                }));
                            }).Unwrap();
                        });
                    });
                }));
            }).Unwrap());
        }
예제 #13
0
        /// <summary>
        /// Adds a Crystal 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="CrystalDialogBase.WaitUntilUnloadedAsync"/>
        /// <para>You have to close the resulting dialog yourself with <see cref="HideCrystalDialogAsync"/>.</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 ShowCrystalDialogAsync(this CrystalWindow window, CrystalDialogBase dialog, CrystalDialogSettings?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.crystalActiveDialogContainer is null)
            {
                throw new InvalidOperationException("Active dialog container could not be found.");
            }

            if (window.crystalInactiveDialogContainer is null)
            {
                throw new InvalidOperationException("Inactive dialog container could not be found.");
            }

            if (window.crystalActiveDialogContainer.Children.Contains(dialog) || window.crystalInactiveDialogContainer.Children.Contains(dialog))
            {
                throw new InvalidOperationException("The provided dialog is already visible in the specified window.");
            }

            settings ??= (dialog.DialogSettings ?? window.CrystalDialogOptions);

            return(HandleOverlayOnShow(settings, window).ContinueWith(z =>
            {
                return 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());
        }
예제 #14
0
        /// <summary>
        /// Gets the current shown dialog in async way.
        /// </summary>
        /// <param name="window">The dialog owner.</param>
        public static Task <TDialog?> GetCurrentDialogAsync <TDialog>(this CrystalWindow window)
            where TDialog : CrystalDialogBase
        {
            window.Dispatcher.VerifyAccess();
            var t = new TaskCompletionSource <TDialog?>();

            window.Dispatcher.Invoke(() =>
            {
                var dialog = window.crystalActiveDialogContainer?.Children.OfType <TDialog>().LastOrDefault();
                t.TrySetResult(dialog);
            });
            return(t.Task);
        }
예제 #15
0
        /// <summary>
        /// Sets the WindowChrome ResizeGripDirection to a CrystalWindow template child.
        /// </summary>
        /// <param name="window">The CrystalWindow.</param>
        /// <param name="name">The name of the template child.</param>
        /// <param name="direction">The direction.</param>
        public static void SetWindowChromeResizeGripDirection([NotNull] this CrystalWindow window, string name, ResizeGripDirection direction)
        {
            if (window is null)
              {
            throw new ArgumentNullException(nameof(window));
              }

              var inputElement = window.GetPart<IInputElement>(name);
              Debug.Assert(inputElement != null, $"{name} is not a IInputElement");
              if (inputElement is not null && WindowChrome.GetResizeGripDirection(inputElement) != direction)
              {
            WindowChrome.SetResizeGripDirection(inputElement, direction);
              }
        }
예제 #16
0
        /// <summary>
        /// Sets the IsHitTestVisibleInChromeProperty to a CrystalWindow template child
        /// </summary>
        /// <param name="window">The CrystalWindow.</param>
        /// <param name="name">The name of the template child.</param>
        /// <param name="hitTestVisible"></param>
        public static void SetIsHitTestVisibleInChromeProperty<T>([NotNull] this CrystalWindow window, string name, bool hitTestVisible = true)
            where T : class
        {
            if (window is null)
              {
            throw new ArgumentNullException(nameof(window));
              }

              var inputElement = window.GetPart<T>(name) as IInputElement;
              Debug.Assert(inputElement != null, $"{name} is not a IInputElement");
              if (inputElement is not null && WindowChrome.GetIsHitTestVisibleInChrome(inputElement) != hitTestVisible)
              {
            WindowChrome.SetIsHitTestVisibleInChrome(inputElement, hitTestVisible);
              }
        }
예제 #17
0
        /// <summary>
        /// Hides a visible Crystal 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="ShowCrystalDialogAsync"/> hasn't been called before.
        /// </exception>
        public static Task HideCrystalDialogAsync(this CrystalWindow window, CrystalDialogBase dialog, CrystalDialogSettings?settings = null)
        {
            window.Dispatcher.VerifyAccess();

            if (window.crystalActiveDialogContainer is null)
            {
                throw new InvalidOperationException("Active dialog container could not be found.");
            }

            if (window.crystalInactiveDialogContainer is null)
            {
                throw new InvalidOperationException("Inactive dialog container could not be found.");
            }

            if (!window.crystalActiveDialogContainer.Children.Contains(dialog) && !window.crystalInactiveDialogContainer.Children.Contains(dialog))
            {
                throw new InvalidOperationException("The provided dialog is not visible in the specified window.");
            }

            window.SizeChanged -= dialog.SizeChangedHandler;

            dialog.OnClose();

            Task closingTask = 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 window.Dispatcher.Invoke(new Func <Task>(() =>
                {
                    window.RemoveDialog(dialog);

                    settings ??= (dialog.DialogSettings ?? window.CrystalDialogOptions);
                    return HandleOverlayOnHide(settings, window);
                }));
            }).Unwrap());
        }
예제 #18
0
        private static CrystalWindow CreateModalExternalWindow(CrystalWindow windowOwner)
        {
            var win = CreateExternalWindow(windowOwner);

            win.Topmost = false;                                           // It is not necessary here because the owner is set
            win.WindowStartupLocation = WindowStartupLocation.CenterOwner; // WindowStartupLocation should be CenterOwner

            // Set Width and Height maximum according Owner
            if (windowOwner.WindowState != WindowState.Maximized)
            {
                win.Width     = windowOwner.ActualWidth;
                win.MaxHeight = windowOwner.ActualHeight;
            }
            else
            {
                // Remove the border on left and right side
                win.BeginInvoke(window =>
                {
                    window.SetCurrentValue(Control.BorderThicknessProperty, new Thickness(0, window.BorderThickness.Top, 0, window.BorderThickness.Bottom));
                    window.SetCurrentValue(CrystalWindow.ResizeBorderThicknessProperty, new Thickness(0, window.ResizeBorderThickness.Top, 0, window.ResizeBorderThickness.Bottom));
                },
                                DispatcherPriority.Loaded);

                // Get the monitor working area
                var monitorWorkingArea = windowOwner.GetMonitorWorkSize();
                if (monitorWorkingArea != default)
                {
                    win.Width     = monitorWorkingArea.Width;
                    win.MaxHeight = monitorWorkingArea.Height;
                }
                else
                {
                    win.Width     = windowOwner.ActualWidth;
                    win.MaxHeight = windowOwner.ActualHeight;
                }
            }

            win.SizeToContent = SizeToContent.Height;

            return(win);
        }
예제 #19
0
        private static Theme? GetCurrentTheme([NotNull] CrystalWindow window)
        {
            if (window is null)
              {
            throw new ArgumentNullException(nameof(window));
              }

              var currentTheme = ThemeManager.Current.DetectTheme(window);
              if (currentTheme is null)
              {
            var application = Application.Current;
            if (application is not null)
            {
              currentTheme = application.MainWindow is null
              ? ThemeManager.Current.DetectTheme(application)
              : ThemeManager.Current.DetectTheme(application.MainWindow);
            }
              }

              return currentTheme;
        }
예제 #20
0
        private static Task HandleOverlayOnHide(CrystalDialogSettings?settings, CrystalWindow window)
        {
            if (window.crystalActiveDialogContainer is null)
            {
                throw new InvalidOperationException("Active dialog container could not be found.");
            }

            Task?result = null;

            if (!window.crystalActiveDialogContainer.Children.OfType <CrystalDialogBase>().Any())
            {
                result = (settings is null || settings.AnimateHide ? window.HideOverlayAsync() : Task.Factory.StartNew(() => window.Dispatcher.Invoke(new Action(window.HideOverlay))));
            }
            else
            {
                var tcs = new TaskCompletionSource <object>();
                tcs.SetResult(null !);
                result = tcs.Task;
            }

            result.ContinueWith(task =>
            {
                window.Invoke(() =>
                {
                    if (window.crystalActiveDialogContainer.Children.Count == 0)
                    {
                        window.SetValue(CrystalWindow.IsCloseButtonEnabledWithDialogPropertyKey, BooleanBoxes.TrueBox);
                        window.RestoreFocus();
                    }
                    else
                    {
                        var onTopShownDialogSettings = window.crystalActiveDialogContainer.Children.OfType <CrystalDialogBase>().LastOrDefault()?.DialogSettings;
                        var isCloseButtonEnabled     = window.ShowDialogsOverTitleBar || onTopShownDialogSettings is null || onTopShownDialogSettings.OwnerCanCloseWithDialog;
                        window.SetValue(CrystalWindow.IsCloseButtonEnabledWithDialogPropertyKey, BooleanBoxes.Box(isCloseButtonEnabled));
                    }
                });
            });

            return(result);
        }
예제 #21
0
        /// <summary>
        /// Adapts the WindowCommands to the theme of the first opened, topmost &amp;&amp; (top || right || left) flyout
        /// </summary>
        /// <param name="window">The CrystalWindow</param>
        /// <param name="flyouts">All the flyouts! Or flyouts that fall into the category described in the summary.</param>
        public static void HandleWindowCommandsForFlyouts(this CrystalWindow window, IEnumerable<Flyout> flyouts)
        {
            var allOpenFlyouts = flyouts.Where(x => x.IsOpen).ToList();

              var anyFlyoutOpen = allOpenFlyouts.Any(x => x.Position != Position.Bottom);
              if (!anyFlyoutOpen)
              {
            window.ResetAllWindowCommandsBrush();
              }

              var topFlyout = allOpenFlyouts
                      .Where(x => x.Position == Position.Top)
                      .OrderByDescending(Panel.GetZIndex)
                      .FirstOrDefault();
              if (topFlyout != null)
              {
            window.UpdateWindowCommandsForFlyout(topFlyout);
              }
              else
              {
            var leftFlyout = allOpenFlyouts
                         .Where(x => x.Position == Position.Left)
                         .OrderByDescending(Panel.GetZIndex)
                         .FirstOrDefault();
            if (leftFlyout != null)
            {
              window.UpdateWindowCommandsForFlyout(leftFlyout);
            }

            var rightFlyout = allOpenFlyouts
                          .Where(x => x.Position == Position.Right)
                          .OrderByDescending(Panel.GetZIndex)
                          .FirstOrDefault();
            if (rightFlyout != null)
            {
              window.UpdateWindowCommandsForFlyout(rightFlyout);
            }
              }
        }
예제 #22
0
        private static SizeChangedEventHandler SetupAndOpenDialog(CrystalWindow window, CrystalDialogBase dialog)
        {
            dialog.SetValue(Panel.ZIndexProperty, (int)(window.overlayBox?.GetValue(Panel.ZIndexProperty) ?? 0) + 1);

            var fixedMinHeight = dialog.MinHeight > 0;
            var fixedMaxHeight = dialog.MaxHeight is not double.PositiveInfinity && dialog.MaxHeight > 0;

            void CalculateMinAndMaxHeight()
            {
                if (!fixedMinHeight)
                {
                    dialog.SetCurrentValue(FrameworkElement.MinHeightProperty, window.ActualHeight / 4.0);
                }

                if (!fixedMaxHeight)
                {
                    dialog.SetCurrentValue(FrameworkElement.MaxHeightProperty, window.ActualHeight);
                }
                else
                {
                    dialog.SetCurrentValue(FrameworkElement.MinHeightProperty, Math.Min(dialog.MinHeight, dialog.MaxHeight));
                }
            }

            CalculateMinAndMaxHeight();

            void OnWindowSizeChanged(object sender, SizeChangedEventArgs args)
            {
                CalculateMinAndMaxHeight();
            }

            window.SizeChanged += OnWindowSizeChanged;

            window.AddDialog(dialog);

            dialog.OnShown();

            return(OnWindowSizeChanged);
        }
예제 #23
0
        private static CrystalWindow CreateExternalWindow(Window?windowOwner = null)
        {
            var window = new CrystalWindow
            {
                ShowInTaskbar            = false,
                ShowActivated            = true,
                Topmost                  = true,
                ResizeMode               = ResizeMode.NoResize,
                WindowStyle              = WindowStyle.None,
                WindowStartupLocation    = WindowStartupLocation.CenterScreen,
                ShowTitleBar             = false,
                ShowCloseButton          = false,
                WindowTransitionsEnabled = false,
                Owner = windowOwner
            };

            // If there is no Application then we need to add our default resources
            if (Application.Current is null)
            {
                window.Resources.MergedDictionaries.Add(new ResourceDictionary {
                    Source = new Uri("pack://application:,,,/Crystal.Themes;component/Styles/Controls.xaml", UriKind.RelativeOrAbsolute)
                });
                window.Resources.MergedDictionaries.Add(new ResourceDictionary {
                    Source = new Uri("pack://application:,,,/Crystal.Themes;component/Styles/Fonts.xaml", UriKind.RelativeOrAbsolute)
                });

                if (windowOwner is not null)
                {
                    var theme = ThemeManager.Current.DetectTheme(windowOwner);
                    if (theme != null)
                    {
                        ThemeManager.Current.ChangeTheme(window, theme);
                    }
                }
            }

            return(window);
        }
예제 #24
0
        private static void ChangeAllWindowCommandsBrush(this CrystalWindow window, Brush? foregroundBrush, Theme? currentAppTheme)
        {
            if (foregroundBrush is null)
              {
            window.LeftWindowCommands?.ClearValue(Control.ForegroundProperty);
            window.RightWindowCommands?.ClearValue(Control.ForegroundProperty);
              }

              // set the theme based on current application or window theme
              var theme = currentAppTheme != null && currentAppTheme.BaseColorScheme == ThemeManager.BaseColorDark
              ? ThemeManager.BaseColorDark
              : ThemeManager.BaseColorLight;

              // set the theme to light by default
              window.LeftWindowCommands?.SetValue(WindowCommands.ThemeProperty, theme);
              window.RightWindowCommands?.SetValue(WindowCommands.ThemeProperty, theme);

              // clear or set the foreground property
              if (foregroundBrush != null)
              {
            window.LeftWindowCommands?.SetValue(Control.ForegroundProperty, foregroundBrush);
            window.RightWindowCommands?.SetValue(Control.ForegroundProperty, foregroundBrush);
              }
        }