private void RenameItem(TextBox tb)
 {
     try
     {
         AGSConnection aGSConnection = this.lbConnections.SelectedItem as AGSConnection;
         if (!(tb.Name == aGSConnection.Name))
         {
             if (AGSConnection.NameAlreadyExists(tb.Text))
             {
                 int    num   = 1;
                 string text  = tb.Text;
                 bool   flag  = true;
                 string text2 = text;
                 while (flag && num < 500)
                 {
                     text2 = string.Format("{0}{1}", text, num);
                     flag  = AGSConnection.NameAlreadyExists(text2);
                     num++;
                 }
                 tb.Text = text2;
             }
             aGSConnection.RemoveFile();
             aGSConnection.Name = tb.Text;
             aGSConnection.SaveToFile();
             ListBoxItem listBoxItem = this.lbConnections.ItemContainerGenerator.ContainerFromItem(aGSConnection) as ListBoxItem;
             if (listBoxItem != null)
             {
                 listBoxItem.ContentTemplate = (base.FindResource("ConnectionTemplate") as DataTemplate);
             }
         }
     }
     catch
     {
     }
 }
        private void mnu_Delete_Click(object sender, RoutedEventArgs e)
        {
            AGSConnection aGSConnection = this.lbConnections.SelectedItem as AGSConnection;

            aGSConnection.RemoveFile();
            App.Connections.Remove(aGSConnection);
            this.lbConnections.Items.Refresh();
        }