wpf comboBox取值问题

时间:2021-07-25 13:05:25

这是获取值后台代码

private void button1_Click(object sender, RoutedEventArgs e)
        {
            combBox = this.comboBox1.SelectedItem as ComboBoxItem;
            combBox1 = this.comboBox2.SelectedItem as ComboBoxItem;
            string type = combBox.Content.ToString();
            string type1 = combBox1.Content.ToString();
            MessageBox.Show(type+type1);
        }
        ComboBoxItem combBox;
        ComboBoxItem combBox1;
        string value = "";
        private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBoxItem cbItem = (ComboBoxItem)(sender as ComboBox).SelectedItem;
            value = cbItem.Content.ToString();
            MessageBox.Show(value);

// string v = (sender as ComboBox).SelectedValue.ToString();
           // string bx=  v as string;
           // MessageBox.Show(bx);
       
        }