WPF: Get Property that a control is Bound to in code behind

前端 未结 2 399
攒了一身酷
攒了一身酷 2021-01-17 12:14

I am trying to find a way to get the Property to which a control is bound (in c#).

If I have the following:



        
2条回答
  •  一生所求
    2021-01-17 13:09

    I think this should do it:

    BindingExpression be = BindingOperations.GetBindingExpression((FrameworkElement)yourComboBox, ((DependencyProperty)Button.SelectedItemProperty));
    string Name = be.ParentBinding.Path.Path;
    

    To give credit where it's due.

提交回复
热议问题