我要填充與用戶輸入在同一個WPF窗口中創建一個列表的組合框創建的列表
主窗口.xaml.cs
//Here I populate the ComboBox with the List
private void Window_Initialized_1(object sender, EventArgs e){
List<string> listaCiudad = EstudioService.obtenerCiudad();
this.ciudadesCBx.Items.Clear();
foreach (String ciudad in listaCiudad){
this.ciudadesCBx.Items.Add(ciudad);
}
}
//Here I get the user input from a textBox called ciudadTxt
//by clicking in the button named agregarCiudadBtn
private void agregarCiudadBtn_Click(object sender, RoutedEventArgs e)
{
EstudioService.agregarCiudad(ciudadTxt.Text);
}
公共類EstudioService
private static List<String> listaCiudad = new List<string>();
public static void agregarCiudad(String ciudad)
{
listaCiudad.Add(ciudad);
}
public static List<String> obtenerCiudad()
{
return listaCiudad;
}
如果測試把'this.ciudadesCBx.Items.Add(ciudadTxt.Text)''裏面的方法agregarCiudadBtn_Click',將其填充組合框? – Sam