public void OnSourceKeyChange(object sender, KeyChangedEventArgs args)
 {
     SourceField sourceField;
     if (sender is SourceField)
     {
         sourceField = sender as SourceField;
         keys[keys.IndexOf(args.OldKey)] = args.NewKey;
         KeysComboBox.Items.Remove(args.OldKey);
         KeysComboBox.Items.Add(args.NewKey);
     }
 }
 public void OnSourceAdded(object sender, EventArgs args)
 {
     SourceField sourceField;
     if (sender is SourceField)
     {
         sourceField = sender as SourceField;
         keys.Remove(sourceField.Key);
         KeysComboBox.Items.Remove(sourceField.Key);
     }
 }
        void AddSourceBtn_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog openFile = new System.Windows.Forms.OpenFileDialog();
            if (openFile.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
                mainController.AddController(openFile.FileName);

                int key = 0;
                SourceField newSource = new SourceField();
                if (sources.Count != 0) {
                    key = keys[keys.Count - 1];
                    while (keys.IndexOf(key) != -1)
                    {
                        key++;
                    }
                    keys.Add(++key);
                } else
                {
                    keys.Add(key);
                }
                sources.Add(key, newSource);
                newSource.Key = key;
                newSource.Path = openFile.FileName;
                newSource.KeyChanged += OnSourceKeyChanged;
                SourceStack.Children.Add(newSource);
                if (SourceAdded != null)
                {
                    SourceAdded(newSource, new EventArgs());
                }
            }
        }