views:

16

answers:

2

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 ???} />
A: 

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.

Jackson Pope
+2  A: 

Use RelativeSource:

<TextBox Text="abc" ToolTip="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Text}" />
Tendlon