Binding to an array element

前端 未结 3 1107
耶瑟儿~
耶瑟儿~ 2020-12-29 10:34

I\'m trying to bind a TextBlock to a specific element in an ObservableCollection. This is what I do right now:

private ObservableCollection arr         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-29 11:10

    No need for the converter. You can bind directly to Arr[0] like this

     
    

    The elements in Arr would need to implement INotifyPropertyChanged though in order to dynamically update.

    Update: To elaborate a bit more:

    public class MyDouble : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
    
        private double _Value;
        public double Value 
        { 
            get { return _Value; } 
            set { _Value = value; OnPropertyChanged("Value"); }
        }
    
        void OnPropertyChanged(string propertyName)
        {
           var handler = PropertyChanged;
           if (handler != null)
           {
              handler(this, new PropertyChangedEventArgs(propertyName));
           }
        }
    }
    

    and then

     ObservableCollection Arr { get; set; }
    

    and bind to

     
    

提交回复
热议问题