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"); }
        }
属性定义

相关文章: