在WPF中,数据从填入的界面写入,然后保存到数据库中;显示界面根据条件从数据库里读取数据,其中有一个ComboBox下拉框,下拉框里项绑定到XML里,应为根据下拉框选项的不同,会影响到某项值是否可以填入问题,故而是用了变更通知将其SelectedValue绑定SelectedValue="{Binding Path=Items[GA001].Value}",其他项根据这个Value的值判断自身的IsEnabled是True还是False。这样一来,在后台将从数据库取出来的数据赋值给该ComboBox后,在页面上ComboBox依旧不显示任何值。这个是什么原因?如果SelectedValue="{Binding Path=Items[GA001].Value}"不写的话,那所选的项就不能自动的去影响其他控件的IsEnabled属性了,有什么办法和使它既显示值,又能用该值应用到变更通知里影响其他控件的属性?

解决方案 »

  1.   

    SelectedValue="{Binding Path=Items[GA001].Value}",这个binding语法怎么看着不对呢 
      

  2.   

    是我没说清不好意思了:
    Item类
    namespace NotifyLibrary
    {
        public class Item : INotifyPropertyChanged
        {
            private string _value;
            public event PropertyChangedEventHandler PropertyChanged;
            public Item()
            { }
            public Item(string val)
            {
                this.Value = val;
            }
            public void NotifyPropertyChanged(string propertyname)
            {
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs(propertyname));
                }
            }
            public string Value
            {
                get
                {
                    return _value;
                }
                set
                {
                    if (_value != value)
                    {
                        _value = value;
                        NotifyPropertyChanged("Value");
                        NotifyPropertyChanged("Enable_Type");
                        NotifyPropertyChanged("Enable_Industry");
                        NotifyPropertyChanged("Enable_Stock");
                        NotifyPropertyChanged("Enable_Other");
                    }
                }
            }
            public bool Enable_Type//根据Value判断Enabled返回值
            {
                get
                {
                    switch (Value)
                    {
                            case:……
                            return true;
                    }
                    return false;
                }
            }
            public bool Enable_Stock
            {
               ……
            }……
    Model类namespace NotifyLibrary
    {
        public class Model
        {
            private Dictionary<string, Item> _xbrlitem = new Dictionary<string, Item>();        public Dictionary<string, Item> Items
            {
                get
                {
                    return _xbrlitem;
                }
            }
            public Model()
            {
                _xbrlitem.Add("GA001", new Item());
                _xbrlitem.Add("GA002", new Item()); 
            }
            public Item this[string iKey]
            {
                get { return _xbrlitem[iKey]; }
            }
        }
    }