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

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

提交回复
热议问题