public static void CreateErrorDialog(string title, string errorMessage, Window owner = null)
        {
            CustomWindow window = null;

            window       = new CustomWindow(new ErrorViewModel(errorMessage, () => window.Close()), "Error");
            window.Owner = owner ?? Application.Current.MainWindow;
            window.MinimizeVisibility = Visibility.Collapsed;
            window.XVisibility        = Visibility.Collapsed;
            window.MaxWidth           = 300;
            window.SizeToContent      = SizeToContent.WidthAndHeight;
            window.ShowDialog();
        }
        public static bool CreateYesNoDialog(string title, string message)
        {
            CustomWindow window = null;
            var          vm     = new YesNoViewModel(message, () => window.Close());

            window       = new CustomWindow(vm, title);
            window.Owner = Application.Current.MainWindow;
            window.MinimizeVisibility = Visibility.Collapsed;
            window.XVisibility        = Visibility.Collapsed;
            window.MaxWidth           = 300;
            window.SizeToContent      = SizeToContent.WidthAndHeight;
            window.ShowDialog();

            return(vm.Result);
        }
        public EditDisplayConfigurationViewModel(ConfigHandler configHandler) : base(configHandler.GetActiveConfig())
        {
            _configHandler = configHandler;

            SaveCommand = new RelayCommand(x => HasConfigChanged(), x => {
                _configHandler.SetActiveConfig(Rows, Columns, Buttons.Select(y => y.Message).ToList());
                _configHandler.SaveConfig();
            });

            CloseCommand = new RelayCommand(x => {
                var hasConfigChanged = HasConfigChanged();
                if (!hasConfigChanged || (hasConfigChanged && DialogFactory.CreateYesNoDialog("Exit Configuration", "Are you sure you would like to exit? You will lose any changes you have made since the last time you saved!")))
                {
                    base.CloseCommand.Execute(null);
                }
            });

            ButtonClickCommand = new RelayCommand(x => {
                CustomWindow window = null;
                var button          = (ButtonViewModel)x;
                var vm       = new EditButtonMessageViewModel(button.Message, () => window.Close());
                window       = new CustomWindow(vm, "Edit Button Message");
                window.Owner = Application.Current.MainWindow;
                window.MinimizeVisibility = Visibility.Collapsed;
                window.XVisibility        = Visibility.Collapsed;
                window.Height             = 160;

                window.ShowDialog();

                if (vm.Result)
                {
                    button.Message = vm.ButtonMessage;
                }
            });

            DisplayLines         = true;
            DisplayWindow.Cursor = null;
            DisplayWindow.Show();
        }
示例#4
0
        public void AppStartup(object sender, StartupEventArgs e)
        {
            _configHandler = new ConfigHandler();

            //The showing of error dialogs must be done after the main window shows since dialogs set the owner to the main window which wouldn't have been created yet
            var rc = _configHandler.LoadConfig();

            var vm = new LauncherViewModel(_configHandler);

            _window = new CustomWindow(vm);
            _window.Show();

            if (rc.ReturnCode != ConfigHandlerReturnCodeType.Success)
            {
                _configHandler.CreateNewConfig();
                if (rc.ReturnCode == ConfigHandlerReturnCodeType.InvalidConfiguration)
                {
                    var result = DialogFactory.CreateYesNoDialog(
                        Constants.C_ConfigErrorTitle,
                        "Could not load configuration file due to it being invalid.\n\nUsing a new configuration for now. Would you like to overwrite the new configuration with the new configuration?"
                        );
                    if (result)
                    {
                        AttemptToSaveConfig();
                    }
                }
                else if (rc.ReturnCode == ConfigHandlerReturnCodeType.FileNotFound)
                {
                    AttemptToSaveConfig();
                }
                else
                {
                    DialogFactory.CreateErrorDialog(Constants.C_ConfigErrorTitle, rc.Reason);
                }
            }
        }