WPF How should I evaluate a property path?

前端 未结 1 1205
醉梦人生
醉梦人生 2021-02-05 21:41

I am writing a custom control, and I have a property path as string (think comboBox.SelectedValuePath).
What is the best way in code to evaluate this string for

相关标签:
1条回答
  • 2021-02-05 22:25

    Create an object that has one dependency property of type object, set the binding on it with your property path as the path, and your arbitrary object as the source. the binding will execute and you can see what (if anything) is at the end of the property path. This is the only way i have found to do this kind of thing in code. you could write a recursive reflection engine that could follow a property path, but its already been done, we use it when we bind. take you five minutes to write :)

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