How to bind to a source inside a ListBox different from the ItemsSource already specified

一曲冷凌霜 提交于 2019-12-02 03:36:21

You can walk up the visual tree and bind to an ancestors datacontext:

{Binding Path=PathToProperty, RelativeSource={RelativeSource AncestorType={x:Type typeOfAncestor}}}

EX:

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

that should give you the datacontext that the listbox has, so assuming your ListOfItems exists in that data context.

Or you can name your control, and then bind to its datacontext by element name:

{Binding ElementName=mySourceElement,Path=ListOfItems}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!