Home > Blockchain >  Is it possible to implement the opposite function of FindAncestor in XAML?
Is it possible to implement the opposite function of FindAncestor in XAML?

Time:12-22

When handling the DataGrid, in code-behind I can walk downwards the visual tree, to cells and their descendants.

In XAML, FindAncestor lets us walk up the visual tree to access a target element that has no Name.

As there is no FindDescendant, I wanted to figure out how to walk downwards, not in code-behind or by MVVM.

CodePudding user response:

No, at least at the moment, such FindDescendant feature is not here. And the main problem you may face trying to implement it by XAML-only is the fact there could be zero or more results matching your criteria, unlike walking the tree up where you see only one parent (or no parent at all for the root element). So the result is a collection, not a single element.

Another aspect of the problem is an ability to alter children representation by template selectors: that way, a parent node should be aware of all alterations down the tree, all the way down (maybe, zillions of levels). However, from system design point, it's better to hide such knowledge and delegate it to children nodes themselves.

Not last and not least: if you alter a parent depending on a child behavior, it may cause a circular dependency/lock if in turn the child is instructed to track the parent behavior via FindAncestor. XAML deadlocks? Thank you but no, thank you!

So, all after all, it could be very arguable ability.

  • Related