private void HandleConnect(object sender, RoutedEventArgs e) { ConnectDialog dialog = new ConnectDialog(); if (dialog.ShowDialog().GetValueOrDefault(false)) { ConnectionInfo info = dialog.ConnectionInfo; if (info != null) { // get rid of the 'Welcome' tab -- has no effect if we've already removed it _tabs.Items.Remove(_welcomeTab); TabItem tab = new TabItem(); TextBlock headerText = new TextBlock(); headerText.Text = dialog.ConnectionName; tab.Header = headerText; QueryControl queryCtrl = new QueryControl(); queryCtrl.Controller = new QueryController(info); tab.Content = queryCtrl; _tabs.Items.Add(tab); _tabs.SelectedItem = tab; } } }