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

前端 未结 2 398
攒了一身酷
攒了一身酷 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.

    0 讨论(0)
  • 2021-01-17 13:14

    Have a look into using BindingExpression

    IE:

    var bindingExpression = this.myComboBox.GetBindingExpression(ComboBox.SelectedItem);
    string bindingPath = bindingExpression.ParentBinding.Path.Path
    

    I see you're using a DXE ComboBox instead of a standard - expecting it derives from a normal .NET control object, you should still have this functionality.

    0 讨论(0)
提交回复
热议问题