日期:2014-05-18  浏览次数:20972 次

wpf combobox数据绑定问题
我定义了两个基础类,ComboboxItemInfo 是用来绑定下拉框数据的。下面是我的基础类和页面绑定的代码。
C# code
 /// <summary>
    /// Combobox 下拉框数据
    /// </summary>
    public class ComboboxItemInfo : INotifyPropertyChanged
    {
       
        private List<string> _itemDisplayInfo;
        /// <summary>
        /// 显示值
        /// </summary>
        public List<string> ItemDisylayInfo
        {
            get { return _itemDisplayInfo; }
            set
            {
                if (_itemDisplayInfo != value)
                {
                    _itemDisplayInfo = value;
                    NotifyPropertyChanged("ItemDisylayInfo");
                }
            }
        }

        private List<string> _itemValueInfo;
        /// <summary>
        /// 实际值
        /// </summary>
        public List<string> ItemValueInfo
        {
            get { return _itemValueInfo; }
            set
            {
                if (_itemValueInfo != value)
                {
                    _itemValueInfo = value;
                    NotifyPropertyChanged("ItemValueInfo");
                }
            }
        }


        //下拉框后面的textbox值
        private string _itemTextBoxValue;
        /// <summary>
        /// Combobox后面的textbox值
        /// </summary>
        public string ItemTextBoxValue
        {
            get { return _itemTextBoxValue; }
            set
            {
                if (_itemTextBoxValue != value)
                {
                    _itemTextBoxValue = value;
                    NotifyPropertyChanged("ItemTextBoxValue");
                }
            }
        }

        //分组名称
        private string _itemgroupName;
        public string ItemGroupName
        {
            get { return _itemgroupName; }
            set
            {
                if (_itemgroupName != value)
                {
                    _itemgroupName = value;
                    NotifyPropertyChanged("ItemGroupName");
                }
            }
        }

        #region INotifyPropertyChanged
        public event PropertyChangedEventHandler PropertyChanged;
        protected void NotifyPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion

    }

    /// <summary>
    /// 
    /// </summary>
    public class KeyValue : INotifyPropertyChanged//, IDataErrorInfo
    {
        public int Index_Check = 0;

        private List<ComboboxItemInfo> _comboBoxKeys;
        /// <summary>
        /// 每个子项的下拉框数据
        /// </summary>
        public List<ComboboxItemInfo> ComboBoxKeys
        {
            get { return _comboBoxKeys; }
            set
            {
                if (_comboBoxKeys != value)
                {
                    _comboBoxKeys = value;
                    NotifyPropertyChanged("ComboBoxKeys");
                }
            }
        }

        private  string _itemName;
        /// <summary>
        /// 每一项名称
        /// </summary>
        public string ItemName
        {
            get { return _itemName; }
            set
            {
                if (_itemName != value)
                {
                    _itemName = value;
                    NotifyPropertyChanged("ItemName");
                }
            }
        }

        //分组名称
        private string _itemgroupName;
        public string ItemGroupName
        {
            get { return _itemgroupName; }
            set
            {
                if (_itemgroupName != value)
                {
                    _itemgroupName = value;