Search code examples
c#wpfxamldata-bindingcollectionviewsource

What is the C# equivalent of XAML's "/" in data-binding paths?


I have 3 entities in entity framework:

collection

subcollection

subsubcollection

The collection entity has a one-to-many relationship with the subcollection entity, which in turn has a one-to-many relationship with the subsubcollection entity. All are observable collections accessed via the CollectionViewSource collectionViewSource.

Now, traversing down the hierarchy of collectionViewSource is easy in XAML; I can just write something like ItemsSource="{Binding collectionViewSource/subcollection/subsubcollection}" to traverse through the current item at each level.

In C#, I can get to the current collection item in my view by writing collectionViewSource.View.CurrentItem. However, I need to be able to delve deeper than this, accessing the current subcollection item to see its subsubcollection. How do I do this?


Solution

  • There is no direct equivalent of / in C#. / does a property traversal, much like ., but takes in to account the binding's current position through parent / child bindings on other controls. You would need to look at the current item of the CollectionViewSource of all bindings through the tree to get the current value. If you don't have access to these controls, or the CollectionViewSources, this may not be simple.