我的xaml上有三个组合框,我首先在页面加载时加载,其余的将在click事件上加载:现在我有DropDownOpened事件,它应该加载组合并保持打开以供用户使用选择,但是它会按照命令来指定项目来源,然后逐步退出
<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 :(得分:0)
它应该保持打开状态,但如果它没有,那么你可以通过使用
强行打开它 cbo2.IsDropDownOpen = true