WPF Show data from multiple DataContexts in ToolTip of ItemsControl

后端 未结 5 2106
清酒与你
清酒与你 2021-01-18 03:54

I am trying to display a tooltip for an item generated by an ItemsControl that needs to pull data from conceptually unrelated sources. For example, say I have a

5条回答
  •  时光取名叫无心
    2021-01-18 04:32

    Second attempt

    Ok, the Relative Source Binding doesn't work in this case. It actually works from a data template, you can find many examples of this on the Internets. But here (you were right, David, in your comment) ToolTip is a special beast that is not placed correctly in the VisualTree (it's a property, not a control per se) and it doesn't have access to the proper name scope to use relative binding.

    After some more searching I found this article, which describes this effect in details and proposes an implementation of a BindableToolTip.

    It might be an overkill, because you have other options -- like using a static property on a class (as in Dabblernl's response) or adding a new instance property to your Item.

    First attempt :)

    You should consult with the Relative Source Binding types (in this cheat sheet for example):

    So your binding will look somehow similar to this:

    {Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}, Path= GlobalText}
    

提交回复
热议问题