/// <summary>
        /// Opens a window and returns only when the dialog is closed.
        /// </summary>
        /// <param name="currentConnection">Optional, the current connection information to show in the dialog</param>
        /// <returns>Captured connection information if closed successfully, null otherwise.</returns>
        public ConnectionInformation ShowDialog(ConnectionInformation currentConnection)
        {
            ConnectionInfoDialogViewModel vm     = CreateViewModel(currentConnection);
            ConnectionInfoDialogView      dialog = CreateView();

            dialog.ViewModel = vm;
            dialog.Owner     = Application.Current.MainWindow;

            bool?result = dialog.ShowDialog();

            if (result.GetValueOrDefault())
            {
                return(CreateConnectionInformation(vm, dialog.Password));
            }

            return(null);
        }
示例#2
0
        /// <summary>
        /// Shows a (modal) dialog which requests connection details from the user
        /// </summary>
        /// <param name="currentConnection">Connection information used to pre-populate fields</param>
        /// <returns>Connection details inputted by user or null if the dialog is dismissed</returns>
        public static ConnectionInformation ShowDialog(ConnectionInformation currentConnection = null)
        {
            var viewModel = new ConnectionInfoDialogViewModel();
            var dialog    = new ConnectionInfoDialogView
            {
                DataContext = viewModel,
                Owner       = Application.Current.MainWindow
            };

            if (null != currentConnection)
            {
                viewModel.ServerUrl = currentConnection.ServerUrl;
                viewModel.Login     = currentConnection.Login;
            }

            bool?result = dialog.ShowDialog();

            if (result.GetValueOrDefault())
            {
                return(new ConnectionInformation(viewModel.ServerUrl, viewModel.Login, viewModel.Password));
            }

            return(null);
        }