How to bind to the class itself in WPF C#

c#, wpf

Solution

You use the "." path:

DisplayMemberBinding="{Binding Path=., Converter={...}}"

"." maps to the current data context.

As it turns out, you can even do these, since the default path is ".":

DisplayMemberBinding="{Binding Converter={...}}"
DisplayMemberBinding="{Binding}" //No converter obviously

I like my original the best, as it is the most explicit and understandable.

Problem

I'm using the code below to bind to the `Depth` property of a the `ColumnSection` class. And I'm using the `LengthConverter` to return an arbitrary result. ``` <GridViewColumn Header="Depth" DisplayMemberBinding="{Binding Path= Depth, Converter={StaticResource LengthConverter}}" Width="60" /> ``` Now what if I wanted to bind to the `ColumnSection` class itself? I will then use a converter to return the Width/Depth ratio and display it as a result. How can I do that?

Original source