简体   繁体   English

从ListBoxItem数据模板获取Listbox属性

[英]Get Listbox properties from ListBoxItem datatemplate

Is there a way to bind a property of the listboxitem to one of it's owning listbox? 有没有一种方法可以将listboxitem的属性绑定到其拥有的列表框之一? I want it in a template so I believe that rules out ElementName. 我希望在模板中使用它,因此我认为可以排除ElementName。

Use the FindAncestor mode of the Binding class. 使用Binding类的FindAncestor模式。 Like this: 像这样:

{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}, Path=YourProperty}

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

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