Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 515
Alain Avatar asked Sep 09 '11 16:09

Alain


4 Answers

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

like image 71
Daniel A. White Avatar answered Oct 21 '22 15:10

Daniel A. White


It binds to the current Datacontext.

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

like image 31
Ashley Grenon Avatar answered Oct 21 '22 16:10

Ashley Grenon


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.

like image 4
svick Avatar answered Oct 21 '22 14:10

svick


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).

like image 1
Daniel Pratt Avatar answered Oct 21 '22 15:10

Daniel Pratt