public ConnectionProfiles()
        {
            InitializeComponent();
            List <ConnectionProfile> list = Config.GetGlobal <List <ConnectionProfile> >("connection.profiles", new List <ConnectionProfile>());

            _model = new ObservableCollection <ConnectionProfileViewModel>(list.ConvertAll((model) => {
                return(new ConnectionProfileViewModel(model));
            }));

            cmbProfiles.ItemsSource = _model;

            cmbConnectionType.ItemsSource       = Enum.GetValues(typeof(ConnectionType));
            cmbConnectionType.SelectionChanged += new SelectionChangedEventHandler(cmbConnectionType_SelectionChanged);

            String lastProfile = Config.GetGlobal <string>("connection.lastprofile", null);

            if (!String.IsNullOrEmpty(lastProfile))
            {
                // Look in the list for the profile with the same name.
                ConnectionProfileViewModel lastUserProfile = _model.FirstOrDefault((item) => { return(item.Name.Equals(lastProfile)); });
                if (lastUserProfile != null)
                {
                    cmbProfiles.SelectedItem = lastUserProfile;
                }
            }
            if (cmbProfiles.SelectedItem == null)
            {
                profileGrid.IsEnabled = false;
            }
        }
        private void DeleteSelected()
        {
            ConnectionProfileViewModel profile = SelectedProfile;

            if (profile != null)
            {
                _model.Remove(profile);
                if (_model.Count > 0)
                {
                    cmbProfiles.SelectedIndex = 0;
                }
            }
        }
        private void AddNewProfile()
        {
            ConnectionProfile model = new ConnectionProfile();

            model.Name = "<New Profile>";

            var profile = new ConnectionProfileViewModel(model);

            _model.Add(profile);
            cmbProfiles.SelectedItem = profile;
            txtName.Focus();
            txtName.SelectAll();
        }
        private void cmbProfiles_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ConnectionProfileViewModel profile = cmbProfiles.SelectedItem as ConnectionProfileViewModel;

            if (profile != null)
            {
                profileGrid.IsEnabled     = true;
                ProfileBorder.DataContext = profile;
            }
            else
            {
                // Clear out the fields
                txtDatabase.Text = "";
                txtName.Text     = "";
                txtServer.Text   = "";
                txtTimeout.Text  = "";
                chkIntegratedSecurity.IsChecked = false;
                // and disable them
                profileGrid.IsEnabled = false;
            }
        }