WPF update binding to element in an array

前端 未结 6 1488
野趣味
野趣味 2021-01-02 16:06

I\'ve searched my little heart out and its entirely possible that I\'m missing something critical and obvious.

I have a BitArray and a series of checkboxes that are

6条回答
  •  無奈伤痛
    2021-01-02 16:44

    You will not be able to set individual array elements using element-index binding. You will need to split the collection up and set up individual properties:

    class TestArray : INotifyPropertyChanged
    {
        private string[] _nameArray = new string[3];
    
        public TestArray()
        {
            _nameArray[1] = "test name";
        }
    
        public string Name
        {
            get { return _nameArray[0]; }
            set { 
                    _nameArray[0] = value; 
                    NotifyPropertyChanged("Name"); 
                }
        }
    }
    

    You will need to use INotifyPropertyChanged as per MSDN (http://msdn.microsoft.com/en-us/library/ms743695.aspx).

提交回复
热议问题