2015-04-03 211 views
0

我有我的xaml三個組合框,我第一個加載頁面加載,其餘的將加載點擊事件:現在我有DropDownOpened事件應加載組合並保持打開供用戶選擇,但它擊中statment指定項目源,但隨後走出的這wpf組合框dropdownned

<Window x:Class="test_combo.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" Height="350" Width="525"> 
    <Grid> 
     <ComboBox Name="cbo1" Margin="40,37,328,250" SelectionChanged="OnComboBoxChanged" /> 
     <ComboBox Name="cbo2" Margin="40,145,328,142" DropDownOpened="cbo2_DropDownOpened" /> 
     <ComboBox Name="cbo3" Margin="40,91,328,196" /> 
    </Grid> 
</Window> 

C#代碼:

public partial class MainWindow : Window 
{ 
    private List<string> comboList = new List<string>(); 
    string[] defaultParam = { City , State ,zip} 

public MainWindow() 
     { 
      InitializeComponent(); 

      foreach(string s in defaultParam) 
      { 
       LoadCombo(s); 
      } 

     } 


     public void LoadCombo(string name) 
     {   
      comboList.Add(name); 
      cbo1.ItemsSource = comboList;   
     } 


     private void OnComboBoxChanged(object sender,SelectionChangedEventArgs e) 
     { 
      string itemSel = (sender as ComboBox).SelectedItem.ToString(); 
      comboList.Remove(itemSel); 
      MessageBox.Show(itemSel); 

     } 

     void cbo2_DropDownOpened(object sender, EventArgs e) 
     { 
      cbo2.ItemsSource = comboList; 
     } 
    } 

回答

0

應該保持開放,但如果沒有,那麼你可以通過使用

cbo2.IsDropDownOpen = true