开发者

WPF: How do I bind the ToolTip property to the value of a siblings ToolTip property?

开发者 https://www.devze.com 2023-03-11 21:46 出处:网络
Assume two controls: 开发者_如何学运维<ParentControl ToolTip=\"{GIMME ChildControl.ToolTip}\">

Assume two controls:

开发者_如何学运维<ParentControl ToolTip="{GIMME ChildControl.ToolTip}">
  <ChildControl ToolTip="Yay! Look at me! I'm bouncing off walls!!!"/>
</ParentControl> 

It's the {GIMME ChildControl.ToolTip} I'm not sure about. I have an inkling it won't work (what is a GIMME anyway), but I'm kind of failing here.

Things I have considered:

  • {Binding RelativeSource=???} - but won't that look in the bound data? I want to reference the child control, not something in the bound data
  • {StaticRecourse useSameForChildControl} - except I'm setting the ToolTip property dynamically in the child control...


Ugly solution that will definitely work - give ChildControl a x:Name value, then bind {Binding ElementName=childElemName, Path=ToolTip}.

(Made into an answer as suggested ;))


Have you considered the MVVM Model? That would allow you to bind both of the controls to the ViewModel?

0

精彩评论

暂无评论...
验证码 换一张
取 消