Example #1
0
        private static Task HandleOverlayOnHide(MetroDialogSettings settings, MetroWindow window)
        {
            Task result = null;

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

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

            return(result);
        }
        protected override Window EnsureWindow(object model, object view, bool isDialog)
        {
            MetroWindow window = null;
            Window      inferOwnerOf;

            if (view is MetroWindow)
            {
                window       = CreateCustomWindow(view, true);
                inferOwnerOf = InferOwnerOf(window);
                if (inferOwnerOf != null && isDialog)
                {
                    window.Owner = inferOwnerOf;
                }
            }

            if (window == null)
            {
                window = CreateCustomWindow(view, false);
            }

            ConfigureWindow(window);
            window.SetValue(Caliburn.Micro.View.IsGeneratedProperty, true);
            inferOwnerOf = InferOwnerOf(window);
            if (inferOwnerOf != null)
            {
                window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                window.Owner = inferOwnerOf;
            }
            else
            {
                window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            }

            return(window);
        }
Example #3
0
 private static Task HandleOverlayOnShow(MetroDialogSettings settings, MetroWindow window)
 {
     return(Task.Factory.StartNew(() =>
     {
         window.Invoke(() =>
         {
             var isCloseButtonEnabled = window.ShowDialogsOverTitleBar || settings == null || settings.OwnerCanCloseWithDialog;
             window.SetValue(MetroWindow.IsCloseButtonEnabledWithDialogPropertyKey, BooleanBoxes.Box(isCloseButtonEnabled));
         });
     })
            .ContinueWith(task =>
     {
         return window.Invoke(() =>
         {
             if (!window.metroActiveDialogContainer.Children.OfType <BaseMetroDialog>().Any())
             {
                 return (settings == null || settings.AnimateShow ? window.ShowOverlayAsync() : Task.Factory.StartNew(() => window.Dispatcher.Invoke(new Action(window.ShowOverlay))));
             }
             else
             {
                 var tcs = new System.Threading.Tasks.TaskCompletionSource <object>();
                 tcs.SetResult(null);
                 return tcs.Task;
             }
         });
     })
            .Unwrap());
 }
Example #4
0
        private static void RemoveDialog(this MetroWindow window, BaseMetroDialog 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.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));
        }
Example #5
0
        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);
            }

            if (window.metroActiveDialogContainer.Children.Count == 0)
            {
                window.RestoreFocus();
            }

            window.SetValue(MetroWindow.IsAnyDialogOpenPropertyKey, window.metroActiveDialogContainer.Children.Count > 0);
        }
Example #6
0
        private static void AddDialog(this MetroWindow window, BaseMetroDialog 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.");
            }

            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);
        }
Example #7
0
        public void ShowPopup(ViewModelBase view, string title, bool ismax = false, bool isDialog = true, bool sideToContent = false, bool isMin = false)
        {
            var p = new MetroWindow {
                WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner, ShowMinButton = false, ShowMaxRestoreButton = false
            };

            p.Content = view.View;
            var tt = view.GetViewTitle();

            if (string.IsNullOrEmpty(title))
            {
                p.Title = tt;
            }
            else
            {
                p.Title = title;
            }
            p.SetValue(Panel.ZIndexProperty, 0);
            p.Topmost = false;
            var uc = view.View as UserControl;

            if (uc.MinHeight != 0)
            {
                p.Height = uc.MinHeight + 20;
            }
            if (uc.MinWidth != 0)
            {
                p.Width = uc.MinWidth + 10;
            }
            p.Icon    = this.Icon;
            p.Owner   = this;
            p.Closed += (s, e) => { view.Closed(); };
            if (ismax)
            {
                p.WindowState = System.Windows.WindowState.Maximized;
                // p.SizeToContent = SizeToContent.WidthAndHeight;
            }
            if (isMin)
            {
                p.ShowMinButton = true;
            }
            if (sideToContent)
            {
                p.SizeToContent = System.Windows.SizeToContent.WidthAndHeight;
                p.ResizeMode    = System.Windows.ResizeMode.CanMinimize;
                p.ShowMinButton = true;
                p.Height       += 1;
                p.Width        += 1;
            }
            if (isDialog)
            {
                p.ShowDialog();
            }
            else
            {
                p.Show();
            }
        }
Example #8
0
        protected override Window EnsureWindow(object model, object view, bool isDialog)
        {
            var window = view as Window;

            if (window == null)
            {
                var metroWindow = new MetroWindow {
                    Content        = view,
                    SizeToContent  = SizeToContent.WidthAndHeight,
                    TitlebarHeight = 0
                };
                window = metroWindow;
                //Interaction.GetBehaviors(metroWindow).Add(new GlowWindowBehavior());
                metroWindow.SetValue(MoveableWindowBehavior.IsEnabledProperty, true);
                metroWindow.SetValue(View.IsGeneratedProperty, true);

                var owner = InferOwnerOf(window);
                if (owner != null)
                {
                    window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                    window.Owner = owner;
                }
                else
                {
                    window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                }
            }
            else
            {
                var owner = InferOwnerOf(window);
                if ((owner != null) && isDialog)
                {
                    window.Owner = owner;
                }
            }

            SetupRxWindow(model, view, window);

            return(window);
        }
Example #9
0
        protected override Window EnsureWindow(object model, object view, bool isDialog)
        {
            MetroWindow window = null;
            Window      inferOwnerOf;

            if (view is MetroWindow)
            {
                window       = this.CreateCustomWindow(view, true);
                inferOwnerOf = this.InferOwnerOf(window);
                if (inferOwnerOf != null && isDialog)
                {
                    window.Owner = inferOwnerOf;
                }
            }

            if (window == null)
            {
                window = this.CreateCustomWindow(view, false);
            }

            this.ConfigureWindow(window);
            window.SetValue(View.IsGeneratedProperty, true);
            inferOwnerOf = this.InferOwnerOf(window);
            if (inferOwnerOf != null)
            {
                try
                {
                    window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                    window.Owner = inferOwnerOf;
                }
                catch
                {
                    window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                }
            }
            else
            {
                window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            }

            if (model is IHaveDisplayName)
            {
                window.Title = (model as IHaveDisplayName).DisplayName;
            }

            return(window);
        }
Example #10
0
        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.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}

            window.SetValue(MetroWindow.IsAnyDialogOpenPropertyKey, true);
        }
        protected override Window EnsureWindow(object model, object view, bool isDialog)
        {
            var window = view as MetroWindow;

            if (window == null)
            {
                window = new MetroWindow
                {
                    Content            = view,
                    SizeToContent      = SizeToContent.Manual,
                    ShowIconOnTitleBar = true,
                    MinHeight          = 150,
                    MinWidth           = 500
                };

                foreach (ResourceDictionary resourceDictionary in Resources)
                {
                    window.Resources.MergedDictionaries.Add(resourceDictionary);
                }
                window.SetValue(View.IsGeneratedProperty, true);
                Window owner = this.InferOwnerOf(window);
                if (owner != null)
                {
                    window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                    window.Owner = owner;
                }
                else
                {
                    window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                }
            }
            else
            {
                Window owner2 = this.InferOwnerOf(window);
                if (owner2 != null && isDialog)
                {
                    window.Owner = owner2;
                }
            }
            return(window);
        }
        protected override Window EnsureWindow(object model, object view, bool isDialog)
        {
            var window = view as MetroWindow;

            if (window == null)
            {
                window = new MetroWindow
                {
                    Content       = view,
                    SizeToContent = SizeToContent.WidthAndHeight,
                    GlowBrush     = resources[3]["AccentColorBrush"] as SolidColorBrush,
                };

                foreach (ResourceDictionary resourceDictionary in resources)
                {
                    window.Resources.MergedDictionaries.Add(resourceDictionary);
                }
                window.SetValue(View.IsGeneratedProperty, true);

                var owner = this.InferOwnerOf(window);
                if (owner != null)
                {
                    window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                    window.Owner = owner;
                }
                else
                {
                    window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                }
            }
            else
            {
                var owner2 = this.InferOwnerOf(window);
                if (owner2 != null && isDialog)
                {
                    window.Owner = owner2;
                }
            }
            return(window);
        }
Example #13
0
        private MetroWindow CreateMetroWindow(object view)
        {
            var metroWindow = new MetroWindow
            {
                Content = view,
                WindowStartupLocation = WindowStartupLocation.CenterScreen
            };

            metroWindow.SetValue(View.IsGeneratedProperty, true);

            AddMetroResources(metroWindow);

            var owner = InferOwnerOf(metroWindow);

            if (owner != null)
            {
                metroWindow.Owner = owner;
                metroWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            }

            return(metroWindow);
        }
Example #14
0
        protected override Window EnsureWindow(object model, object view, bool isDialog)
        {
            MetroWindow window = null;
            Window      inferOwnerOf;

            if (view is MetroWindow)
            {
                window       = CreateCustomWindow(view, true);
                inferOwnerOf = InferOwnerOf(window);
                if (inferOwnerOf != null && isDialog)
                {
                    window.Owner = inferOwnerOf;
                }
            }

            if (window == null)
            {
                window = CreateCustomWindow(view, false);
            }

            ConfigureWindow(window);
            window.SetValue(View.IsGeneratedProperty, true);
            inferOwnerOf = InferOwnerOf(window);
            if (inferOwnerOf != null)
            {
                window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                window.Owner = inferOwnerOf;
            }
            else
            {
                window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            }
            window.BorderThickness = new Thickness(2);
            window.BorderBrush     = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(154, 34, 46));

            return(window);
        }
Example #15
0
        protected override Window EnsureWindow(object model, object view, bool isDialog)
        {
            var window = view as MetroWindow;

            if (window == null)
            {
                window = new MetroWindow {
                    Content = view,
                };
                window.SetValue(View.IsGeneratedProperty, true);
                window.Resources.MergedDictionaries.Add(this.themeManager.GetThemeResources());

                var owner = this.InferOwnerOf(window);
                if (owner != null)
                {
                    window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                    window.ShowInTaskbar         = false;
                    window.Owner = owner;
                }
                else
                {
                    window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                }
            }
            else
            {
                var owner2 = this.InferOwnerOf(window);
                if (owner2 != null && isDialog)
                {
                    window.ShowInTaskbar = false;
                    window.Owner         = owner2;
                }
            }

            return(window);
        }
Example #16
0
        protected override Window EnsureWindow(object model, object view, bool isDialog)
        {
            var metroWindow = view as MetroWindow;

            if (metroWindow == null)
            {
                var    userControl = view as UserControl;
                double minHeight   = 150D;
                double minWidth    = 500D;
                double?height      = null;
                double?width       = null;
                if (userControl != null)
                {
                    minHeight = userControl.MinHeight;
                    minWidth  = userControl.MinWidth;
                    height    = userControl.Height;
                    width     = userControl.Width;
                }

                metroWindow = new MetroWindow
                {
                    Content            = view,
                    SizeToContent      = SizeToContent.Manual,
                    MinHeight          = minHeight,
                    MinWidth           = minWidth,
                    SaveWindowPosition = true
                };
                if (height.HasValue && width.HasValue)
                {
                    metroWindow.Height = height.Value;
                    metroWindow.Width  = width.Value;
                }

                foreach (var resourceDict in _resources)
                {
                    metroWindow.Resources.MergedDictionaries.Add(resourceDict);
                }

                metroWindow.SetValue(View.IsGeneratedProperty, true);
                var owner = this.InferOwnerOf(metroWindow);
                if (owner != null)
                {
                    metroWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                    metroWindow.Owner = owner;
                }
                else
                {
                    metroWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                }
            }
            else
            {
                var owner = this.InferOwnerOf(metroWindow);
                if (owner != null && isDialog)
                {
                    metroWindow.Owner = owner;
                }
            }

            return(metroWindow);
        }