我有一些簡單的示例WinForms代碼,我嘗試將其轉換爲WPF。這個想法是,如果某個項目被選中,則更改組合框中的項目,如果發生這種情況,則再次下拉組合框。在的WinForms代碼:WPF中的WinForms ComboBox.DroppedDown的等價示例
if (list.Text.Equals("C>>"))
{
comboBox1.Items.Clear();
comboBox1.Items.Add("<<");
comboBox1.Items.Add("C1");
comboBox1.Items.Add("C2");
comboBox1.Items.Add("C3");
comboBox1.Items.Add("C4");
comboBox1.Items.Add("C5");
comboBox1.Items.Add("C6");
comboBox1.DroppedDown = true;
}
雖然我雖然,這將是一個相當簡單的改變,使用
private void hotListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (hotListBox.SelectedItem != null)
{
if (hotListBox.SelectedItem.Equals("b >>"))
{
hotListBox.ItemsSource = secondList;
hotListBox.IsDropDownOpen = true;
}
else if (hotListBox.SelectedItem.Equals("<<"))
{
hotListBox.ItemsSource = initialList;
hotListBox.IsDropDownOpen = true;
}
else if (hotListBox.SelectedItem.Equals("d >>"))
{
hotListBox.ItemsSource = thirdList;
hotListBox.IsDropDownOpen = true;
}
}
}
在WPF
似乎並沒有以相同的方式工作。我想知道如果有人知道如何做到這一點?
正如在註釋中指出的那樣,我應該說ComboBox中的項目按預期更新,但它不會再次在WPF代碼中下拉。
乾杯,
編輯:更新的代碼
更多關於什麼不工作的信息?組合框中是否顯示新項目?之後不打開嗎? – Bubblewrap 2010-09-08 14:29:32
新項目在ComboBox中可見,它不會隨後打開,而是使用WPF代碼打開,而使用WinForms代碼打開。 – 2010-09-08 14:35:53