问题描述
我想做这样的事情:
Value="{x:Bind MyCustomDependencyProp, RelativeSource={RelativeSource TemplatedParent}}"
这可能吗?有什么性能上的好处?
Is that possible? Are there any performance benefits?
使用TemplateBinding似乎不起作用,并且具有自定义DependencyProperty,如SO上其他地方所述:
Using TemplateBinding does not seem to work, with a custom DependencyProperty as described elsewhere here on SO: https://stackoverflow.com/a/8657453
推荐答案
RelativeSource(带有x:Bind)是不支持,因此这种特定情况将是不可能的(至少目前是这样)。
RelativeSource (with x:Bind) is not supported, therefore this particular scenario won't be possible (at the moment, at least).
使用TemplateBinding或 standard 绑定到TemplatedParent(如上所述)是解决方法。
Using TemplateBinding or standard Binding to TemplatedParent (as you mentioned) are workarounds.
TemplateBinding已经绑定,因此根据此
TemplateBinding is already an optimized version of Binding so it shouldn't be that big of a deal according to this Build 2015 session by Sam Spencer.
这篇关于是否可以将已编译的绑定(x:Bind)与相对源,模板化父级一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!