【问题标题】:How to get relative source of item in ItemTemplate如何在 ItemTemplate 中获取项目的相对来源
【发布时间】:2010-04-14 17:19:20
【问题描述】:

我有一个带有指定 ItemTemplate 的 ListBox。并且 ItemTemplate 包含自己的 ListView,我想在该 ListView 中显示一个集合,这实际上是 ListBox 的项目的属性。

您能告诉我如何进行绑定吗?我正在考虑 RelativeSource 的事情,但我不知道正确的语法是什么样的......

【问题讨论】:

    标签: binding datatemplate relativesource


    【解决方案1】:

    没关系,我找到了答案。

    应该是这样的:

    ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor,
                                         AncestorType={x:Type ListBoxItem}},Path=DataContext.YourCollectionProperty}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-02
      • 1970-01-01
      • 1970-01-01
      • 2015-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-06
      相关资源
      最近更新 更多