开发者

What does Value="{Binding}" do? [duplicate]

This question already has answers here: Closed 11 years a开发者_Go百科go.

Possible Duplicate:

WPF Binding Syntax Question

I've been using this syntax all over the place, and I thought I knew what it did, but now I have no idea.

Value="{Binding}"

I am having huge trouble searching for this syntax online because of course the curly brackets are ignored.

For instance:

<Style x:Key="GridCell" TargetType="{x:Type TextBlock}">
    <Setter Property="ToolTip" Value="{Binding}}"/>
</Style>

When applied as a style to a textblock is binding the tooltip to the unfomatted (unconverted) property that the textblock content (text) is bound to.


Its data binding value to the root of the window or control's DataContext.


It binds to the current Datacontext.

I suggest you take a look at the WPF Databinding Cheat Sheet. Should be a handy reference.


The syntax {Binding <something>} creates a new Binding using the Binding markup extension.

Specifically, {Binding} creates the Binding object with empty path. And since the paths are relative to the current DataContext, this means binding to it.


The documentation refers to {Binding} as the "empty binding syntax". It binds the property to the entire object referenced by the DataContext.

It may be worth noting that a control inherits the DataContext of its parent element (unless you set it directly).


It is how WPF links your data to the control. See MSDN for more detail. http://msdn.microsoft.com/en-us/library/ms752347.aspx


It all depends where in the your Element Tree you are using this. By default it means current DataContext. But if you are already inside your ListBox, then it means ListBox's DataContext. Which is different from Root/Main DataContext.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜