public void OpenWindow(ViewModelBase viewModel, Action onClosed)
 {
     var childWindow = new ChildWindow
                           {
                               Content = GetViewForViewModel(viewModel)
                           };
     var canClose = viewModel as ICanClose;
     if (canClose != null)
     {
         canClose.RequestClose += (s,e) => childWindow.Close();
     }
     childWindow.Closed += (s,e) => onClosed();
     childWindow.Show();
 }
Beispiel #2
0
        /// <summary>
        /// Executed when the a key is presses when the window is open.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="e">Key event args.</param>
        private void ChildWindow_KeyDown(object sender, KeyEventArgs e)
        {
            ChildWindow ew = sender as ChildWindow;

            Debug.Assert(ew != null, "ChildWindow instance is null.");

            // Ctrl+Shift+F4 closes the ChildWindow
            if (e != null && !e.Handled && e.Key == Key.F4 &&
                ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) &&
                ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift))
            {
                ew.Close();
                e.Handled = true;
            }
        }
        private void Print(ChildWindow window)
        {
            var doc = new PrintDocument();

            doc.PrintPage += (s, ea) =>
            {
                ea.PageVisual = new Image { Source = new BitmapImage(Uri) };
                ea.HasMorePages = false;
            };

            doc.EndPrint += (sender, args) => window.Close();

            var settings = new PrinterFallbackSettings { ForceVector = false };

            doc.Print(Title, settings);
        }
Beispiel #4
0
        private async void Save(ChildWindow window)
        {
            var user = new User
            {
                UserName = Title,
                Roles = new[] { Role },
            };

            IsBusy = true;
            var task = await repository.UpdateUser(user);
            IsBusy = false;
            if (task.Succeed)
            {
                Confirmed = true;
            }
            window.Close();
        }
Beispiel #5
0
        private void OnConfigCommandMessage(ConfigCommandMessage message)
        {
            var window = new ChildWindow();
            var contentControl = new NewEditServer();
            contentControl.DataContext = new EditServerDetailViewModel(message.Server);
            window.Content = contentControl;
            window.Closed += (s, e) =>
            {
                Messenger.Default.Unregister<CloseEditServerMessage>(this);
                Application.Current.RootVisual.SetValue(Control.IsEnabledProperty, true);
            };

            Messenger.Default.Register<CloseEditServerMessage>(this, (m) =>
            {
                window.DialogResult = false;
                window.Close();
            });

            window.Show();
        }
        private async void Save(ChildWindow window)
        {
            ValidateName();
            ValidateSize();
            ValidateK();
            ValidatePriceOpt();
            ValidateCount();
            ValidateNd();
            ValidateLength();
            ValidatePriceIcome();

            if (HasErrors) return;

            var changed = PropsToProduct();

            IsBusy = true;
            var task = await repository.SaveAsync(changed);
            IsBusy = false;
            if (task.Succeed)
            {
                var args = new ProductUpdatedEventArgs(task.Result, false);
                eventAggregator.GetEvent<ProductUpdatedEvent>().Publish(args);
                Confirmed = true;
                window.Close();
            }
        }
        void OnShutdownAttempted(IGuardClose guard, ChildWindow view, CancelEventArgs e)
        {
            if (actuallyClosing)
            {
                actuallyClosing = false;
                return;
            }

            bool runningAsync = false, shouldEnd = false;

            guard.CanClose(canClose =>{
                if(runningAsync && canClose)
                {
                    actuallyClosing = true;
                    view.Close();
                }
                else e.Cancel = !canClose;

                shouldEnd = true;
            });

            if (shouldEnd)
                return;

            runningAsync = e.Cancel = true;
        }
Beispiel #8
0
        public static ChildWindow PopupContent(string title, object content, IEnumerable<Button> buttons)
        {
            if (CurrentPopup != null)
                return null;

            var msgBox = new ChildWindow();
            CurrentPopup = msgBox;
            msgBox.Style = Application.Current.Resources["PopupMessageWindow"] as Style;
            msgBox.BorderBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0xBA, 0xD2, 0xEC));
            msgBox.Title = title;

            msgBox.MaxWidth = Application.Current.Host.Content.ActualWidth * 0.5;

            StackPanel panel = new StackPanel();
            panel.Children.Add(new ContentPresenter() { Content = content });

            StackPanel buttonPanel = new StackPanel() { Margin = new Thickness(20), Orientation = Orientation.Horizontal, HorizontalAlignment = HorizontalAlignment.Center };

            if (buttons != null)
            {
                foreach (Button b in buttons)
                {
                    b.Click += (s, e) =>
                    {
                        msgBox.Close();
                    };
                    buttonPanel.Children.Add(b);
                }

            }
            else
            {
                var closeButton = new Button { Content = Labels.ButtonClose, HorizontalAlignment = HorizontalAlignment.Center, };
                closeButton.Click += (s, e) =>
                {
                    msgBox.Close();
                };
                buttonPanel.Children.Add(closeButton);

            }

            panel.Children.Add(buttonPanel);
            msgBox.Content = panel;

            msgBox.IsTabStop = true;
            msgBox.Show();
            msgBox.Focus();

            PopupManager.CloseActivePopup();
            return msgBox;
        }
Beispiel #9
0
        public static ChildWindow PopupMessage(string title, string message, string closeButtonLabel, bool closeWindow)
        {
            if (CurrentPopup != null)
                return null;

            var msgBox = new ChildWindow();
            CurrentPopup = msgBox;
            
            msgBox.Style = Application.Current.Resources["PopupMessageWindow"] as Style;
            msgBox.BorderBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0xBA, 0xD2, 0xEC));
            msgBox.Title = title;
            msgBox.MaxWidth = Application.Current.Host.Content.ActualWidth * 0.5;

            StackPanel content = new StackPanel();
            content.Children.Add(new TextBlock() { Text = message, Margin = new Thickness(20), Foreground = new SolidColorBrush(Colors.White), FontSize = 14, HorizontalAlignment=HorizontalAlignment.Center });

            Button closeButton = new Button { Content = closeButtonLabel, FontSize = 14, HorizontalAlignment = HorizontalAlignment.Center, Margin = new Thickness(20) };
            closeButton.Click += (s, o) =>
                                     {
                                         msgBox.Close();
                                         if (closeWindow)
                                         {
                                             BrowserWindow.Close();
                                         }
                                     };
            content.Children.Add(closeButton);
            msgBox.Content = content;
            msgBox.IsTabStop = true;
            
            msgBox.Show();
            msgBox.Focus();
            
            _currentWindow = msgBox;
            PopupManager.CloseActivePopup();
            return msgBox;
        }
        private async void Save(ChildWindow window)
        {
            Error = null;

            ValidateName();
            ValidatePassword();
            if (HasErrors) return;

            var user = new User
            {
                UserName = Name,
                Roles = new [] { Role },
                Password = Password,
            };

            IsBusy = true;
            var task = await repository.CreateUser(user);
            IsBusy = false;
            if (task.Succeed)
            {
                Confirmed = true;
                window.Close();
            }
            else
            {
                Error = task.ErrorMessage;
            }
        }
Beispiel #11
0
        private void OnConfigCommandMessage(ConfigCommandMessage message)
        {
            var window = new ChildWindow();
            var contentControl = new NewEditServer();
            contentControl.DataContext = new EditServerDetailViewModel(message.Server);
            window.Content = contentControl;
            window.SizeToContent = SizeToContent.WidthAndHeight;
            window.Topmost = true;
            window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            window.ResizeMode = ResizeMode.NoResize;
            window.Title = "Edit Server";

            Messenger.Default.Register<CloseEditServerMessage>(this, (m) =>
            {
                window.DialogResult = false;
                window.Close();
            });

            window.ShowDialog();
            Messenger.Default.Unregister<CloseEditServerMessage>(this);
        }
        /// <summary>
        /// Called when shutdown attempted.
        /// </summary>
        /// <param name="rootModel">The root model.</param>
        /// <param name="view">The view.</param>
        /// <param name="handleShutdownModel">The handler for the shutdown model.</param>
        /// <param name="e">The <see cref="System.ComponentModel.CancelEventArgs"/> instance containing the event data.</param>
        protected virtual void OnShutdownAttempted(IPresenter rootModel, ChildWindow view, Action<ISubordinate, Action> handleShutdownModel, CancelEventArgs e)
        {
            if (_actuallyClosing || rootModel.CanShutdown())
            {
                _actuallyClosing = false;
                return;
            }

            bool runningAsync = false;

            var custom = rootModel as ISupportCustomShutdown;
            if (custom != null && handleShutdownModel != null)
            {
                var shutdownModel = custom.CreateShutdownModel();
                var shouldEnd = false;

                handleShutdownModel(
                    shutdownModel,
                    () =>
                    {
                        var canShutdown = custom.CanShutdown(shutdownModel);
                        if (runningAsync && canShutdown)
                        {
                            _actuallyClosing = true;
                            view.Close();
                        }
                        else e.Cancel = !canShutdown;

                        shouldEnd = true;
                    });

                if (shouldEnd)
                    return;
            }

            runningAsync = e.Cancel = true;
        }