开发者

WPF - databinding to a property of same control

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


Use RelativeSource:

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


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜