private void SwitchLanguage(int factoryIndex) { // Define the new factory // Note: LanguageFactory objects have some "memory" of what components were added to them. // Defining a new factory like this "clears" that memory. currentFactory = (LanguageFactory)Activator.CreateInstance(allFactories[factoryIndex].GetType()); // Switch out the warning warningLabel.Content = currentFactory.GetWarning(); // Replace the components list with the new one currentComponents = currentFactory.GetAvalibleComponents(); while (!componentComboBox.Items.IsEmpty) { componentComboBox.Items.RemoveAt(0); } for (int x = 0; x < currentComponents.Length; x++) { componentComboBox.Items.Add(currentComponents[x]); } // Clear out the list of components componentList.Content = ""; // Reset the selected index componentComboBox.SelectedIndex = 0; }