Binding to an array element

前端 未结 3 1090
耶瑟儿~
耶瑟儿~ 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:07

    you can use this way in my case I want to binding the visibility from an boolean array: code behind:

    using System.Windows;
    public static readonly DependencyProperty ButtonVisibleProperty =
            DependencyProperty.Register("ButtonVisible", typeof(BindingList), typeof(BaseWindow), new PropertyMetadata(new BindingList()));
     public BindingList ButtonVisible 
        { 
            get { return (BindingList)GetValue(BaseWindow.ButtonVisibleProperty); }
            set 
            {
                SetValue(BaseWindow.ButtonVisibleProperty, value);
                OnPropertyChanged("ButtonVisible");  
            } 
        }
    

    and in Xaml:

    Visibility=""{Binding Path=ButtonVisible[0], RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
    

    beware! the ancestorType depend of your Ancestor in my case is a window

提交回复
热议问题