有没有办法跟踪代码中的绑定? [英] Is there a way to follow a binding in code?
问题描述
如果我有一个Binding,它有一个属性路径,数据源可以在代码中执行,找到值?
If i have a Binding which has a property path and the data source can i execute it in code, to find the value?
我正在尝试的路径跟踪可能会相当复杂,包括收集查找和多个级别。
The path that i am trying to follow can be quite complicated, including collection lookup and multiple levels.
有一个黑客:
创建一个内容控件
使用BindingOperations.SetBinding()
create a content control use BindingOperations.SetBinding()
然后检索内容
是否有更好的方式?
推荐答案
您可以避免使用 ContentControl
您自己的非常简单的类直接从 DependencyObject
派生,并提供了一个单独的 DependencyProperty
,然后您可以使用捆绑。除此之外,不,没有什么更好的方法 - WPF中的绑定机制与依赖属性的概念非常相关,绑定不能真正成为刚刚评估的独立表达式。
You can avoid using a ContentControl
, and write your own very simple class that derives directly from DependencyObject
, and provides a single DependencyProperty
, which you can then target with the binding. Aside from that, no, there isn't any better way - binding machinery in WPF is very much tied into the concept of dependency properties, and a binding cannot really be a "free-standing expression" that is just evaluated.
这篇关于有没有办法跟踪代码中的绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!