예제 #1
0
        private FileInfo SaveResponse(FileInfo arg)
        {
            FileInfo             _ret         = null;
            SaveFileConfirmation _newFileInfo = new SaveFileConfirmation()
            {
                Title = "Save configuration file", FilePath = arg.FullName
            };

            SaveFileInteractionEvent?.Invoke(this, new InteractionRequestedEventArgs(_newFileInfo, () => _ret = String.IsNullOrEmpty(_newFileInfo.FilePath) ?  null  : new FileInfo(_newFileInfo.FilePath)));
            return(_ret);
        }
        private void _vmSaveFileInteractionEvent(object sender, InteractionRequestedEventArgs e)
        {
            SaveFileConfirmation _confirmation = e.Context as SaveFileConfirmation;

            if (_confirmation == null)
            {
                return;
            }
            string _msg = $"Click Yes to save configuration to {_confirmation.FilePath}, No to slecet new file, Cancel to cancel";

            //switch (MessageBox.Show(_confirmation.Title, _msg, MessageBoxButton.YesNoCancel, MessageBoxImage.Question, MessageBoxResult.Cancel))
            switch (MessageBox.Show(_msg, _confirmation.Title, MessageBoxButton.YesNoCancel, MessageBoxImage.Question, MessageBoxResult.Cancel))
            {
            case MessageBoxResult.None:
            case MessageBoxResult.OK:
            case MessageBoxResult.Yes:
                break;

            case MessageBoxResult.Cancel:
                _confirmation.FilePath = string.Empty;
                break;

            case MessageBoxResult.No:
                OpenFileDialog _dialog = new OpenFileDialog()
                {
                    AddExtension    = true,
                    CheckPathExists = true,
                    DefaultExt      = ".xml",
                    Filter          = "Configuration (.xml)|*.xml",
                    FileName        = _confirmation.FilePath,
                    Title           = "Save file as ..",
                    CheckFileExists = false,
                    ValidateNames   = true,
                };
                _confirmation.FilePath = _dialog.ShowDialog().GetValueOrDefault(false) ? _dialog.FileName : string.Empty;
                e.Callback();
                break;

            default:
                break;
            }
        }