Explain WPF relative binding / relative resource?


When we define bindings we need at least two elements target and source. But many times rather than defining binding between two elements we would like to define binding with reference to the current element i.e. RELATIVELY.
For instance let’s say we have a WPF border and we would like height and width of the broder to
be same. So for this scenario the target and source are the same, the WPF border itself. So we
can define the binding using “RelativeSource” as shown in the below code. You can see it uses
“Self” binding mode to bind the element to itself.

<Border BorderBrush="Black" BorderThickness="1" Height="139" Width="{Binding Height, RelativeSource={RelativeSource Self}}"/>