TwoWay Binding of a ComboBox to a static property

后端 未结 2 1092
南方客
南方客 2021-01-15 02:53

-------EDIT------

So, i figured that my code is correct and so are the code snippets from all of your answers. Thanks for that. My

2条回答
  •  猫巷女王i
    2021-01-15 03:30

    Checked just in a sample project, works fine

    public class ViewModel
    {
        static ViewModel()
        {
            Items=new ObservableCollection();
            SelectedItem = "222";
            Items.Add("111");
            Items.Add("222");
            Items.Add("333");
            Items.Add("444");
            Items.Add("555");
        }
        private static string _selectedItem;
        public static string SelectedItem
        {
            get { return _selectedItem; }
            set { _selectedItem = value;
                MessageBox.Show("Item " + value + " was selected");
            }
        }
    
        private static ObservableCollection _items;
        public static ObservableCollection Items
        {
            get { return _items; }
            set { _items = value; }
        }
    }
    

    and xaml

    
    
        
            
        
        
        
    
    

    I have uploaded sample.

提交回复
热议问题