Reputation: 4311
I have a control (let's say a textbox) and I want bind the value of one property (let's say tooltip) to value of another property in same control(let's say text).
i want something like belowing but I dont know how can I bind the tooltip to text of same control :
<textBox text="abc" tooltip={Binding ???} />
Upvotes: 14
Views: 7864
Reputation: 1904
Use RelativeSource:
<TextBox Text="abc" ToolTip="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Text}" />
Upvotes: 39
Reputation: 14640
If you use the MVVM pattern you can expose a property on the ViewModel and then bind both to the same property:
<textBox text="{Binding Text}" tooltip="{Binding Text}" />
And in the ViewModel:
public string Text { get return "abc"; }
This allows you to unit test that the value presented is correct.
Upvotes: 1