wpf ComboBox 获取选中项的文本内容

时间:2021-12-02 23:04:56

一:根据数据源类型获取选中项

类:

public class Region
{
public int REGION_ID { get; set; }
public string REGION_CODE { get; set; }
public string REGION_NAME { get; set; }
public int PARENT_ID { get; set; }
}

数据源绑定:

            //绑定国家
cbe_Nationality.ItemsSource = new List<Region>()
{
new Region() { REGION_ID=, REGION_NAME="中国"},
new Region() { REGION_ID=, REGION_NAME="美国"}
};
cbe_Nationality.SelectedValuePath = "REGION_ID";
cbe_Nationality.DisplayMemberPath = "REGION_NAME";
this.cbe_Nationality.SelectedIndex = ;

获取选中项 并 取出其中的文本显示内容:

            //获取绑定信息
Region cbi = (this.cbe_Nationality.SelectedItem) as Region;

获取了选中项并转换成对象,就可以获取里面的值及文本了