MVVM模式下做的省市区的级联效果。通过改变ComboBox执行命令改变市,区。
解决主要问题就是默认选中第一项
1.首先要定义一个属性,继承自INotifyPropertyChanged接口。我这里用的Prism框架中集成的NotificationObject
/// <summary> /// 省 /// </summary> private ObservableCollection<MyArea> provinceBindingList; public ObservableCollection<MyArea> ProvinceBindingList { get { return provinceBindingList; } set { provinceBindingList = value; this.RaisePropertyChanged("ProvinceBindingList"); } } /// <summary> /// 市 /// </summary> private ObservableCollection<MyArea> cityBindingList; public ObservableCollection<MyArea> CityBindingList { get { return cityBindingList; } set { cityBindingList = value; this.RaisePropertyChanged("CityBindingList"); } } /// <summary> /// 区 /// </summary> private ObservableCollection<MyArea> areaBindingList; public ObservableCollection<MyArea> AreaBindingList { get { return areaBindingList; } set { areaBindingList = value; this.RaisePropertyChanged("AreaBindingList"); } } /// <summary> /// 默认选择请选择项 /// </summary> public readonly MyArea defaultSelectItem; /// <summary> /// 添加城市选择项 /// </summary> private MyArea selectCity; public MyArea SelectCity { get { return selectCity; } set { selectCity = value; this.RaisePropertyChanged("SelectCity"); } }