我有這個問題,當我運行應用程序時,我看到項目「紅色」,「藍色」,「黃色」的列表框。但是,當我鍵入「黑色」textBox1並按Button1項目不添加。任何想法爲什麼?WPF列表框 - 數據綁定問題
public partial class Window1 : Window
{
private static ArrayList myItems = new ArrayList();
public Window1()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
listBox1.ItemsSource = myItems;
myItems.Add("red");
myItems.Add("blue");
myItems.Add("yellow");
}
private void button1_Click(object sender, RoutedEventArgs e)
{
myItems.Add(textBox1.Text);
}
}
優秀的答案,完美的作品,謝謝+++ – markoniuss 2010-09-13 08:27:59