wpf bind all sliders ‘ IsEnabledProperty in a array

42 Views Asked by At

First I am new to wpf and a rookie programer... I have a userControl displays over 100 sliders, I want to manage their "IsEnabledProperty" in an array, I am thinking to use binding expression, but don't know how! Here is my code with binding expression:

I have set dataContext m_ViewModel.

 public bool[] ControlerEnable
        {
            set => SetProperty(ref _controlerEnable, value);
            get => _controlerEnable;
        }
             List<Slider> _sliders = GetVisualChild<Slider>(this._grid);
            for (int i = 0; i < _sliders.Count; ++i)
            {
                BindingExpression value= _sliders[i].GetBindingExpression(Slider.ValueProperty);
                string sliderValue = value.ParentBinding.Path.Path;
                int nIndex = GetIndex(sliderValue);
                Binding binding = new Binding("m_ViewModel.ControlerEnable[nIndex]");  //question here
                BindingOperations.SetBinding(_sliders[i], Slider.IsEnabledProperty, binding);
                _sliders[i].MouseDoubleClick += Slider_MouseDoubleClick;
            }

Can I use index in path like that?

0

There are 0 best solutions below