Is it possible to use compiled binding (x:Bind) with Relative Source, Templated Parent
Asked Answered
W

1

3

I'd like to do something like this is a Style:

Value="{x:Bind MyCustomDependencyProp, RelativeSource={RelativeSource TemplatedParent}}"

Is that possible? Are there any performance benefits?

Using TemplateBinding does not seem to work, with a custom DependencyProperty as described elsewhere here on SO: https://stackoverflow.com/a/8657453

Webster answered 3/9, 2015 at 9:38 Comment(0)
C
3

RelativeSource (with x:Bind) is not supported, therefore this particular scenario won't be possible (at the moment, at least).

Using TemplateBinding or standard Binding to TemplatedParent (as you mentioned) are workarounds.

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.

Capper answered 3/9, 2015 at 11:4 Comment(6)
Actually RelativeSource is supported, only Mode=FindAncestor is not.Conversable
@JustinXL Hmmm are you sure? cloud.githubusercontent.com/assets/2558207/9658304/…Capper
@JustinXL of course :) but the question was about using x:Bind with RelativeSource TemplatedParentCapper
@JustinXL yeah, I edited to make it clearer what I meant. Thanks!Capper
Thank you both for great reply and comments!Webster
@JasperHedegaardBojsen if it answered your question, don't forget to mark it as answer. :)Capper

© 2022 - 2024 — McMap. All rights reserved.