开发者

ElementName vs. FindVisualAncestor

开发者 https://www.devze.com 2023-01-09 13:25 出处:网络
How does the XAML engine search for Binding.ElementName vs RelativeSource.AncestorType. It would take a huge different when I am searching for a parent Window or Page (that x:Name was set in it), if

How does the XAML engine search for Binding.ElementName vs RelativeSource.AncestorType.

It would take a huge different when I am searching for a parent Window or Page (that x:Name was set in it), if the ElementName searches up (meaning starting from near current element up the tree levels children, then it's better to use the AncestorType since it won't search the siblings, just the ancestors. But if it (the ElementName) starts from to top of the visual tree and goes deeper and deeper, then of course I should get it by the ElementName property.

Bottom line: my question is whether the Binding.ElementName is search for the name from the top of the tree, or from th开发者_JAVA百科e point of the binding upwards.

So please share me with your knowledge.


FYI: As far as I found from my shallow research with .NET reflector, it seems that the ElementName search searches from the current element upwards, so it's better using RelativeSource and AncestorType (FindAncestor mode).
HTH

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号