【问题标题】:wpf combo box dropdownopnedwpf组合框下拉打开
【发布时间】:2015-04-03 16:07:03
【问题描述】:

我的 xaml 上有三个组合框,第一个在页面加载时加载,其余的将在点击事件时加载:现在我有 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;
        }
    }

【问题讨论】:

    标签: c# .net wpf


    【解决方案1】:

    它应该保持打开状态,但如果没有,那么您可以使用强制打开它

     cbo2.IsDropDownOpen = true
    

    【讨论】:

      猜你喜欢
      • 2014-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多