简体   繁体   English

在数据绑定路径中,XAML的“/”的C#等价物是什么?

[英]What is the C# equivalent of XAML's “/” in data-binding paths?

I have 3 entities in entity framework: 我在实体框架中有3个实体:

collection 采集

subcollection 子集合

subsubcollection 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 . 所有都是通过CollectionViewSource collectionViewSource访问的可观察CollectionViewSource collectionViewSource

Now, traversing down the hierarchy of collectionViewSource is easy in XAML; 现在,在XAML中,遍历collectionViewSource的层次结构很容易; I can just write something like ItemsSource="{Binding collectionViewSource/subcollection/subsubcollection}" to traverse through the current item at each level. 我可以写一些像ItemsSource="{Binding collectionViewSource/subcollection/subsubcollection}"来遍历每个级别的当前项目。

In C#, I can get to the current collection item in my view by writing collectionViewSource.View.CurrentItem . 在C#中,我可以通过编写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? 我该怎么做呢?

There is no direct equivalent of / in C#. 在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. 您需要通过树查看所有绑定的CollectionViewSource的当前项以获取当前值。 If you don't have access to these controls, or the CollectionViewSources, this may not be simple. 如果您无权访问这些控件或CollectionViewSources,则可能并不简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM